11import numpy as np
2-
2+ import tensorflow as tf
33import deepprofiler .imaging .cropping
4-
4+ from keras . applications import inception_resnet_v2
55
66def repeat_channels (crops , labels , repeats ):
7+ crops = crops [np .newaxis , :]
8+ labels = labels [np .newaxis , :]
9+ print ('crops begin' , crops .shape )
10+ print ('crops begin' , labels .shape )
11+ print (repeats )
712 crops = np .reshape (crops , (crops .shape [0 ] * crops .shape [3 ], crops .shape [1 ], crops .shape [2 ], 1 ))
13+ print (crops .shape )
814 crops = np .tile (crops , (1 , 1 , 1 , repeats ))
15+ print (crops .shape , crops .__class__ )
16+ print (labels .shape )
917 labels = np .tile (labels , (repeats , 1 ))
18+ print (labels .shape )
19+ #crops = tf.image.resize_images(crops, size=(299, 299))
20+ print (crops .shape , crops .__class__ )
1021 return crops , labels
22+ #return inception_resnet_v2.preprocess_input(crops), labels
23+ #def crop_transform(crop_ph, image_size):
24+ #crops_shape = crops.shape
25+ #resized_crops = tf.image.resize_images(crops, size=(299, 299))
26+ #print(resized_crops.shape)
27+ #reordered_channels = tf.transpose(resized_crops, [3, 0, 1, 2])
28+ #print(reordered_channels.shape)
29+ #reshaped_data = tf.reshape(reordered_channels, shape=[-1, 299, 299, 1])
30+ #print(reshaped_data.shape)
31+ #rgb_data = tf.image.grayscale_to_rgb(reordered_channels)
32+ #print(rgb_data.shape)
33+ #return inception_resnet_v2.preprocess_input(rgb_data), labels
1134
1235
1336class GeneratorClass (deepprofiler .imaging .cropping .CropGenerator ):
@@ -21,6 +44,7 @@ def generate(self, sess, global_step=0):
2144 crops = data [0 ]
2245 labels = data [1 ] # TODO: enable multiple targets
2346 crops , labels = repeat_channels (crops , labels , self .config ["dataset" ]["images" ]["channel_repeats" ])
47+ crops = crops .eval (session = sess )
2448 global_step += 1
2549 yield (crops , labels )
2650
@@ -30,5 +54,22 @@ class SingleImageGeneratorClass(deepprofiler.imaging.cropping.SingleImageCropGen
3054 def generate (self , session , global_step = 0 ):
3155 crops = self .image_pool
3256 labels = self .label_pool
33- crops , labels = repeat_channels (crops , labels , self .config ["dataset" ]["images" ]["channel_repeats" ])
34- yield [crops , labels ]
57+ #new_crops = np.array([[[[]]]])
58+ #new_labels = np.array([[[[]]]])
59+ for i in range (crops .shape [0 ]):
60+ crop , label = repeat_channels (crops [i , :, :, :], labels [i , :], self .config ["dataset" ]["images" ]["channel_repeats" ])
61+ #crop = crop.eval(session=session)
62+ crop = session .run (tf .image .resize_images (crop , size = (299 , 299 )))
63+ if i == 0 :
64+ new_crops = crop
65+ new_labels = label
66+ else :
67+ new_crops = np .concatenate ((new_crops , crop ), axis = 0 )
68+ new_labels = np .concatenate ((new_labels , label ), axis = 0 )
69+
70+ #print('last shape', crop.shape, label.shape)
71+ #print('generator shapes', new_crops.shape, new_labels.shape)
72+ #new_crops = new_crops.eval(session=session)
73+ #crops, labels = repeat_channels(crops, labels, self.config["dataset"]["images"]["channel_repeats"])
74+ #crops = crops.eval(session=session)
75+ yield [new_crops , new_labels ]
0 commit comments