Commit f8a7fc77 by Tiago de Freitas Pereira

### Updated the resize algorithm

parent 35180690
 ... ... @@ -190,17 +190,21 @@ class Base(object): bob.ip.base.scale(copy, dst) dst = numpy.reshape(dst, self.input_shape[1:4]) else: # dst = numpy.resize(data, self.bob_shape) # Scaling with numpy, because bob is c,w,d instead of w,h,c dst = numpy.zeros(shape=self.bob_shape) #dst = numpy.resize(data, self.bob_shape) # Scaling with numpy, because bob is c,w,d instead of w,h,c #dst = numpy.zeros(shape=(data.shape[0], data.shape[1], 3)) #dst[:, :, 0] = data[:, :, 0] #dst[:, :, 1] = data[:, :, 0] #dst[:, :, 2] = data[:, :, 0] # TODO: LAME SOLUTION if data.shape[0] != 3: # GRAY SCALE IMAGES IN A RGB DATABASE step_data = numpy.zeros(shape=(3, data.shape[0], data.shape[1])) step_data[0, ...] = data[:, :] step_data[1, ...] = data[:, :] step_data[2, ...] = data[:, :] data = step_data #if data.shape[0] != 3: # GRAY SCALE IMAGES IN A RGB DATABASE # step_data = numpy.zeros(shape=(3, data.shape[0], data.shape[1])) #step_data = numpy.zeros(shape=(3, data.shape[0], data.shape[1])) #step_data[0, ...] = data[:, :, 0] #step_data[1, ...] = data[:, :, 0] #step_data[2, ...] = data[:, :, 0] #data = step_data dst = numpy.zeros(shape=(self.bob_shape)) bob.ip.base.scale(data, dst) return dst ... ...
 ... ... @@ -222,6 +222,7 @@ def test_siamesecnn_trainer(): loss=loss, learning_rate=constant(0.01, name="regular_lr"), optimizer=tf.train.GradientDescentOptimizer(0.01),) trainer.train() embedding = Embedding(train_data_shuffler("data", from_queue=False)['left'], graph['left']) eer = dummy_experiment(validation_data_shuffler, embedding) ... ...
 ... ... @@ -43,16 +43,16 @@ def scratch_network_embeding_example(train_data_shuffler, reuse=False, get_embed if get_embedding: embedding = tf.nn.l2_normalize(prelogits, dim=1, name="embedding") return embedding return embedding, None else: logits = slim.fully_connected(prelogits, 10, activation_fn=None, scope='logits', weights_initializer=initializer, reuse=reuse) logits_prelogits = dict() logits_prelogits['logits'] = logits logits_prelogits['prelogits'] = prelogits #logits_prelogits = dict() #logits_prelogits['logits'] = logits #logits_prelogits['prelogits'] = prelogits return logits_prelogits return logits, prelogits def test_cnn_tfrecord_embedding_validation(): ... ... @@ -102,12 +102,12 @@ def test_cnn_tfrecord_embedding_validation(): validation_data_shuffler = TFRecord(filename_queue=filename_queue_val, batch_size=2000) graph = scratch_network_embeding_example(train_data_shuffler) validation_graph = scratch_network_embeding_example(validation_data_shuffler, reuse=True, get_embedding=True) graph, prelogits = scratch_network_embeding_example(train_data_shuffler) validation_graph,_ = scratch_network_embeding_example(validation_data_shuffler, reuse=True, get_embedding=True) # Setting the placeholders # Loss for the softmax loss = MeanSoftMaxLossCenterLoss(n_classes=10, add_regularization_losses=False) loss = MeanSoftMaxLossCenterLoss(n_classes=10, factor=0.1) # One graph trainer trainer = Trainer(train_data_shuffler, ... ... @@ -118,16 +118,22 @@ def test_cnn_tfrecord_embedding_validation(): temp_dir=directory) learning_rate = constant(0.01, name="regular_lr") trainer.create_network_from_scratch(graph=graph, validation_graph=validation_graph, loss=loss, learning_rate=learning_rate, optimizer=tf.train.GradientDescentOptimizer(learning_rate), prelogits=prelogits ) trainer.train() os.remove(tfrecords_filename) os.remove(tfrecords_filename_val) """ assert True tf.reset_default_graph() del trainer ... ... @@ -149,4 +155,4 @@ def test_cnn_tfrecord_embedding_validation(): tf.reset_default_graph() shutil.rmtree(directory) assert len(tf.global_variables())==0 """
 ... ... @@ -154,8 +154,7 @@ def test_trainable_variables(): ) # Loading two layers from the "old" model external_model = os.path.join(step1_path, "model.ckp") trainer.load_variables_from_external_model(external_model, var_list=['conv1', 'fc1']) trainer.load_variables_from_external_model(step1_path, var_list=['conv1', 'fc1']) conv1_restored = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope='conv1')[0].eval(session=trainer.session)[0] ... ...
 ... ... @@ -92,7 +92,7 @@ def test_tripletmemory_shuffler(): def test_disk_shuffler(): train_data, train_labels = get_dummy_files() batch_shape = [None, 125, 125, 3] batch_shape = [None, 250, 250, 3] data_shuffler = Disk(train_data, train_labels, input_shape=batch_shape, ... ... @@ -101,13 +101,13 @@ def test_disk_shuffler(): batch = data_shuffler.get_batch() assert len(batch) == 2 assert batch[0].shape == (2, 125, 125, 3) assert batch[0].shape == (2, 250, 250, 3) def test_siamesedisk_shuffler(): train_data, train_labels = get_dummy_files() batch_shape = [None, 125, 125, 3] batch_shape = [None, 250, 250, 3] data_shuffler = SiameseDisk(train_data, train_labels, input_shape=batch_shape, ... ... @@ -116,14 +116,14 @@ def test_siamesedisk_shuffler(): batch = data_shuffler.get_batch() assert len(batch) == 3 assert batch[0].shape == (2, 125, 125, 3) assert batch[1].shape == (2, 125, 125, 3) assert batch[0].shape == (2, 250, 250, 3) assert batch[1].shape == (2, 250, 250, 3) def test_tripletdisk_shuffler(): train_data, train_labels = get_dummy_files() batch_shape = [None, 125, 125, 3] batch_shape = [None, 250, 250, 3] data_shuffler = TripletDisk(train_data, train_labels, input_shape=batch_shape, ... ... @@ -132,9 +132,9 @@ def test_tripletdisk_shuffler(): batch = data_shuffler.get_batch() assert len(batch) == 3 assert batch[0].shape == (1, 125, 125, 3) assert batch[1].shape == (1, 125, 125, 3) assert batch[2].shape == (1, 125, 125, 3) assert batch[0].shape == (1, 250, 250, 3) assert batch[1].shape == (1, 250, 250, 3) assert batch[2].shape == (1, 250, 250, 3) def test_triplet_fast_selection_disk_shuffler(): ... ...
 ... ... @@ -96,7 +96,7 @@ def test_disk_shuffler(): train_data, train_labels = get_dummy_files() batch_shape = [None, 125, 125, 3] batch_shape = [None, 250, 250, 3] batch_size = 2 data_augmentation = ImageAugmentation() ... ... @@ -107,7 +107,7 @@ def test_disk_shuffler(): batch = data_shuffler.get_batch() assert len(batch) == 2 assert batch[0].shape == (batch_size, 125, 125, 3) assert batch[0].shape == (batch_size, 250, 250, 3) placeholders = data_shuffler("data", from_queue=False) assert placeholders.get_shape().as_list() == batch_shape ... ... @@ -117,7 +117,7 @@ def test_siamesedisk_shuffler(): train_data, train_labels = get_dummy_files() batch_shape = [None, 125, 125, 3] batch_shape = [None, 250, 250, 3] batch_size = 2 data_augmentation = ImageAugmentation() data_shuffler = SiameseDisk(train_data, train_labels, ... ... @@ -127,7 +127,7 @@ def test_siamesedisk_shuffler(): batch = data_shuffler.get_batch() assert len(batch) == 3 assert batch[0].shape == (batch_size, 125, 125, 3) assert batch[0].shape == (batch_size, 250, 250, 3) placeholders = data_shuffler("data", from_queue=False) assert placeholders['left'].get_shape().as_list() == batch_shape ... ... @@ -138,7 +138,7 @@ def test_tripletdisk_shuffler(): train_data, train_labels = get_dummy_files() batch_shape = [None, 125, 125, 3] batch_shape = [None, 250, 250, 3] batch_size = 1 data_augmentation = ImageAugmentation() data_shuffler = TripletDisk(train_data, train_labels, ... ... @@ -147,8 +147,8 @@ def test_tripletdisk_shuffler(): data_augmentation=data_augmentation) batch = data_shuffler.get_batch() assert len(batch) == 3 assert batch[0].shape == (1, 125, 125, 3) assert len(batch) == 3 assert batch[0].shape == (1, 250, 250, 3) placeholders = data_shuffler("data", from_queue=False) assert placeholders['anchor'].get_shape().as_list() == batch_shape ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!