def sample(self, nb_samples): sampled_character_folders = random.sample(self.character_folders, nb_samples) random.shuffle(sampled_character_folders) example_inputs = np.zeros( (self.batch_size, nb_samples * self.nb_samples_per_class, np.prod(self.img_size)), dtype=np.float32) example_outputs = np.zeros( (self.batch_size, nb_samples * self.nb_samples_per_class), dtype=np.float32 ) #notice hardcoded np.float32 here and above, change it to something else in tf for i in range(self.batch_size): labels_and_images = get_shuffled_images( sampled_character_folders, range(nb_samples), nb_samples=self.nb_samples_per_class) sequence_length = len(labels_and_images) labels, image_files = zip(*labels_and_images) angles = np.random.uniform(-self.max_rotation, self.max_rotation, size=sequence_length) shifts = np.random.uniform(-self.max_shift, self.max_shift, size=sequence_length) example_inputs[i] = np.asarray([load_transform(filename, angle=angle, s=shift, size=self.img_size).flatten() \ for (filename, angle, shift) in zip(image_files, angles, shifts)], dtype=np.float32) example_outputs[i] = np.asarray(labels, dtype=np.int32) return example_inputs, example_outputs
def sample(self, nb_samples): sampled_character_folders = random.sample(self.character_folders, nb_samples) random.shuffle(sampled_character_folders) example_inputs = np.zeros((self.batch_size, nb_samples * self.nb_samples_per_class, np.prod(self.img_size)), dtype=np.float32) example_outputs = np.zeros((self.batch_size, nb_samples * self.nb_samples_per_class), dtype=np.float32) #notice hardcoded np.float32 here and above, change it to something else in tf for i in range(self.batch_size): labels_and_images = get_shuffled_images(sampled_character_folders, range(nb_samples), nb_samples=self.nb_samples_per_class) sequence_length = len(labels_and_images) labels, image_files = zip(*labels_and_images) angles = np.random.uniform(-self.max_rotation, self.max_rotation, size=sequence_length) shifts = np.random.uniform(-self.max_shift, self.max_shift, size=sequence_length) example_inputs[i] = np.asarray([load_transform(filename, angle=angle, s=shift, size=self.img_size).flatten() \ for (filename, angle, shift) in zip(image_files, angles, shifts)], dtype=np.float32) example_outputs[i] = np.asarray(labels, dtype=np.int32) return example_inputs, example_outputs
def startom(): noise_input2 = tf.placeholder(tf.float32, shape=[None, latent_dim2]) decoder2 = tf.matmul(tf.concat([noise_input2,y2], 1), weights2['decoder_h1']) + biases2['decoder_b1'] decoder2 = tf.nn.tanh(decoder2) decoder2 = tf.matmul(decoder2, weights2['decoder_out']) + biases2['decoder_out'] decoder2 = tf.nn.sigmoid(decoder2) n = 9 noise_dim=2 filename='/var/www/html/search/images/input.png' example_inputs = np.asarray([load_transform(filename, size=(28,28)).flatten() \ ], dtype=np.float32) canvas_recon0 = np.empty((28 * (1), 28 * 1)) canvas_recon1 = np.empty((28 * (1), 28 * 1)) canvas_recon2 = np.empty((28 * (1), 28 * 1)) canvas_recon3 = np.empty((28 * (1), 28 * 1)) canvas_recon4 = np.empty((28 * (1), 28 * 1)) canvas_recon5 = np.empty((28 * (1), 28 * 1)) canvas_recon6 = np.empty((28 * (1), 28 * 1)) canvas_recon7 = np.empty((28 * (1), 28 * 1)) canvas_recon8 = np.empty((28 * (1), 28 * 1)) for i in range(n): ztest = np.random.uniform(-1., 1., size=[1, noise_dim]) g = sess.run(decoder2, feed_dict={noise_input2: ztest,y2:example_inputs }) g = (g + 1.) / 2. g = -1 * (g - 1) if i==0: canvas_recon0[ 0:(1) * 28, 0:(1) * 28] = g.reshape([28, 28]) plt.figure(figsize=(1, 1)) plt.axis('off') plt.imshow(canvas_recon0, origin="upper", cmap="gray") plt.savefig('/var/www/html/search/images/out%d.png'%(i+1) ) if i==1: canvas_recon1[ 0:(1) * 28, 0:(1) * 28] = g.reshape([28, 28]) plt.figure(figsize=(1, 1)) plt.axis('off') plt.imshow(canvas_recon1, origin="upper", cmap="gray") plt.savefig('/var/www/html/search/images/out%d.png'%(i+1) ) if i==2: canvas_recon2[ 0:(1) * 28, 0:(1) * 28] = g.reshape([28, 28]) plt.figure(figsize=(1, 1)) plt.axis('off') plt.imshow(canvas_recon2, origin="upper", cmap="gray") plt.savefig('/var/www/html/search/images/out%d.png'%(i+1) ) if i==3: canvas_recon3[ 0:(1) * 28, 0:(1) * 28] = g.reshape([28, 28]) plt.figure(figsize=(1, 1)) plt.axis('off') plt.imshow(canvas_recon3, origin="upper", cmap="gray") plt.savefig('/var/www/html/search/images/out%d.png'%(i+1) ) if i==4: canvas_recon4[ 0:(1) * 28, 0:(1) * 28] = g.reshape([28, 28]) plt.figure(figsize=(1, 1)) plt.axis('off') plt.imshow(canvas_recon4, origin="upper", cmap="gray") plt.savefig('/var/www/html/search/images/out%d.png'%(i+1) ) if i==5: canvas_recon5[ 0:(1) * 28, 0:(1) * 28] = g.reshape([28, 28]) plt.figure(figsize=(1, 1)) plt.axis('off') plt.imshow(canvas_recon5, origin="upper", cmap="gray") plt.savefig('/var/www/html/search/images/out%d.png'%(i+1) ) if i==6: canvas_recon6[ 0:(1) * 28, 0:(1) * 28] = g.reshape([28, 28]) plt.figure(figsize=(1, 1)) plt.axis('off') plt.imshow(canvas_recon6, origin="upper", cmap="gray") plt.savefig('/var/www/html/search/images/out%d.png'%(i+1) ) if i==7: canvas_recon7[ 0:(1) * 28, 0:(1) * 28] = g.reshape([28, 28]) plt.figure(figsize=(1, 1)) plt.axis('off') plt.imshow(canvas_recon7, origin="upper", cmap="gray") plt.savefig('/var/www/html/search/images/out%d.png'%(i+1) ) if i==8: canvas_recon8[ 0:(1) * 28, 0:(1) * 28] = g.reshape([28, 28]) plt.figure(figsize=(1, 1)) plt.axis('off') plt.imshow(canvas_recon8, origin="upper", cmap="gray") plt.savefig('/var/www/html/search/images/out%d.png'%(i+1) )