MCPcopy
hub / github.com/hanzhanggit/StackGAN / save_super_images

Function save_super_images

demo/demo.py:105–161  ·  view source on GitHub ↗
(sample_batchs, hr_sample_batchs,
                      captions_batch, batch_size,
                      startID, save_dir)

Source from the content-addressed store, hash-verified

103
104
105def save_super_images(sample_batchs, hr_sample_batchs,
106 captions_batch, batch_size,
107 startID, save_dir):
108 if not os.path.isdir(save_dir):
109 print('Make a new folder: ', save_dir)
110 mkdir_p(save_dir)
111
112 # Save up to 16 samples for each text embedding/sentence
113 img_shape = hr_sample_batchs[0][0].shape
114 for j in range(batch_size):
115 if not re.search('[a-zA-Z]+', captions_batch[j]):
116 continue
117
118 padding = np.zeros(img_shape)
119 row1 = [padding]
120 row2 = [padding]
121 # First row with up to 8 samples
122 for i in range(np.minimum(8, len(sample_batchs))):
123 lr_img = sample_batchs[i][j]
124 hr_img = hr_sample_batchs[i][j]
125 hr_img = (hr_img + 1.0) * 127.5
126 re_sample = scipy.misc.imresize(lr_img, hr_img.shape[:2])
127 row1.append(re_sample)
128 row2.append(hr_img)
129 row1 = np.concatenate(row1, axis=1)
130 row2 = np.concatenate(row2, axis=1)
131 superimage = np.concatenate([row1, row2], axis=0)
132
133 # Second 8 samples with up to 8 samples
134 if len(sample_batchs) > 8:
135 row1 = [padding]
136 row2 = [padding]
137 for i in range(8, len(sample_batchs)):
138 lr_img = sample_batchs[i][j]
139 hr_img = hr_sample_batchs[i][j]
140 hr_img = (hr_img + 1.0) * 127.5
141 re_sample = scipy.misc.imresize(lr_img, hr_img.shape[:2])
142 row1.append(re_sample)
143 row2.append(hr_img)
144 row1 = np.concatenate(row1, axis=1)
145 row2 = np.concatenate(row2, axis=1)
146 super_row = np.concatenate([row1, row2], axis=0)
147 superimage2 = np.zeros_like(superimage)
148 superimage2[:super_row.shape[0],
149 :super_row.shape[1],
150 :super_row.shape[2]] = super_row
151 mid_padding = np.zeros((64, superimage.shape[1], 3))
152 superimage =\
153 np.concatenate([superimage, mid_padding, superimage2], axis=0)
154
155 top_padding = np.zeros((128, superimage.shape[1], 3))
156 superimage =\
157 np.concatenate([top_padding, superimage], axis=0)
158
159 fullpath = '%s/sentence%d.jpg' % (save_dir, startID + j)
160 superimage = drawCaption(np.uint8(superimage), captions_batch[j])
161 scipy.misc.imsave(fullpath, superimage)
162

Callers 1

demo.pyFile · 0.70

Calls 2

mkdir_pFunction · 0.90
drawCaptionFunction · 0.70

Tested by

no test coverage detected