highdimensionals / deep-image-matching Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Hi @talalsoms
I'm recreating the steps your FineTuning_main.ipynb notebook on a set of different images. Everything works great until I tune the model weights. I'm on Python 3.5.3, TF 1.15 and Keras 2.3.1 on a Debian 9 with one GPU K80
Here are my parameters:
## Hyperparameters
batch_size = 32
# Triplet loss computation parameter
margin = 0.1
#minimum number of samples required in a class in the train dataset, for that class, to be considered
min_count_th = 0
#samples set aside, per class, for validation. They are also samples set aside, per class, for test.
samples_per_class_val = 100
samples_per_class_test = 100
#Learning rate
learning_rate = 1e-5
# Total epochs for training
num_epochs = 300
# Epochs for re-sampling of triplets
epochs_per_triplets = 1
# Candidate triplet images generated per triplet of labels
triplets_fixed_class = 70
# Number of op candidate triplets selected for training
top_triplets = 1600
# Augmentation - True or False
augmentation_flag = False
# Length of feature vectors (512 for VGG, 2048 for Resnet50)
len_features = 512
######################################
## Pooling type: 'mac' or 'spoc'
pooling_type = 'spoc'
######################################
## Layers to be fine-tuned
# Fine-tune pca layer
tune_pca = True
# Fine-tune conv5 layer
tune_conv5 = True
# For naming files
tag = 'mac-keras-new-data-margin01'
trainingLayer = 'conv5_pca'
Classes
Number of classes: 5
Number of training samples: 3100
Number of validation samples: 500
Number of test samples: 500
Data split into train, validation and test dataset, based on shape, successfully...
Ranked triplets
Generating feature vectors...
Feature vectors genereated for all train vectors...
Candidate triplets generated...
Ranking the triplets...
500 triplets evaluated...
1000 triplets evaluated...
Number of candidates with non-zero loss: 1400
Total number of candidates: 1400
Candidate triplets ranked and saved, successfully...
Model
Loading Deep Image Retrieval (pre-trained weights) model...
Done!
Model: "model_8"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_17 (InputLayer) (None, 224, 224, 3) 0
__________________________________________________________________________________________________
input_18 (InputLayer) (None, 224, 224, 3) 0
__________________________________________________________________________________________________
input_19 (InputLayer) (None, 224, 224, 3) 0
__________________________________________________________________________________________________
vgg16 (Model) (None, 7, 7, 512) 14714688 input_17[0][0]
input_18[0][0]
input_19[0][0]
__________________________________________________________________________________________________
query_pooling (Lambda) (None, 512) 0 vgg16[1][0]
__________________________________________________________________________________________________
relevant_pooling (Lambda) (None, 512) 0 vgg16[2][0]
__________________________________________________________________________________________________
irrelevant_pooling (Lambda) (None, 512) 0 vgg16[3][0]
__________________________________________________________________________________________________
query_norm1 (Lambda) (None, 512) 0 query_pooling[0][0]
__________________________________________________________________________________________________
relevant_norm1 (Lambda) (None, 512) 0 relevant_pooling[0][0]
__________________________________________________________________________________________________
irrelevant_norm1 (Lambda) (None, 512) 0 irrelevant_pooling[0][0]
__________________________________________________________________________________________________
model_7 (Model) multiple 262656 query_norm1[0][0]
relevant_norm1[0][0]
irrelevant_norm1[0][0]
__________________________________________________________________________________________________
query_norm2 (Lambda) (None, 512) 0 model_7[1][0]
__________________________________________________________________________________________________
relevant_norm2 (Lambda) (None, 512) 0 model_7[2][0]
__________________________________________________________________________________________________
irrelevant_norm2 (Lambda) (None, 512) 0 model_7[3][0]
__________________________________________________________________________________________________
lambda_4 (Lambda) (None, 3, 512) 0 query_norm2[0][0]
relevant_norm2[0][0]
irrelevant_norm2[0][0]
==================================================================================================
Total params: 14,977,344
Trainable params: 7,342,080
Non-trainable params: 7,635,264
__________________________________________________________________________________________________
The error
The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
Epoch 1/300
43/50 [========================>.....] - ETA: 32s - loss: 0.0997
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-27-53724cbf2a60> in <module>
41 #===========================================
42
---> 43 history = model.fit_generator(train_generator,steps_per_epoch = batches_per_epoch,epochs = num_epochs,callbacks=[resampleTriplets,checkpoint])#, lr_scheduler
~/env/lib/python3.5/site-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
89 warnings.warn('Update your `' + object_name + '` call to the ' +
90 'Keras 2 API: ' + signature, stacklevel=2)
---> 91 return func(*args, **kwargs)
92 wrapper._original_function = func
93 return wrapper
~/env/lib/python3.5/site-packages/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
1730 use_multiprocessing=use_multiprocessing,
1731 shuffle=shuffle,
-> 1732 initial_epoch=initial_epoch)
1733
1734 @interfaces.legacy_generator_methods_support
~/env/lib/python3.5/site-packages/keras/engine/training_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
183 batch_index = 0
184 while steps_done < steps_per_epoch:
--> 185 generator_output = next(output_generator)
186
187 if not hasattr(generator_output, '__len__'):
~/env/lib/python3.5/site-packages/keras/utils/data_utils.py in get(self)
740 "`use_multiprocessing=False, workers > 1`."
741 "For more information see issue #1638.")
--> 742 six.reraise(*sys.exc_info())
~/env/lib/python3.5/site-packages/six.py in reraise(tp, value, tb)
694 if value.__traceback__ is not tb:
695 raise value.with_traceback(tb)
--> 696 raise value
697 finally:
698 value = None
~/env/lib/python3.5/site-packages/keras/utils/data_utils.py in get(self)
709 try:
710 future = self.queue.get(block=True)
--> 711 inputs = future.get(timeout=30)
712 self.queue.task_done()
713 except mp.TimeoutError:
/usr/lib/python3.5/multiprocessing/pool.py in get(self, timeout)
606 return self._value
607 else:
--> 608 raise self._value
609
610 def _set(self, i, obj):
/usr/lib/python3.5/multiprocessing/pool.py in worker(inqueue, outqueue, initializer, initargs, maxtasks, wrap_exception)
117 job, i, func, args, kwds = task
118 try:
--> 119 result = (True, func(*args, **kwds))
120 except Exception as e:
121 if wrap_exception:
~/env/lib/python3.5/site-packages/keras/utils/data_utils.py in next_sample(uid)
648 The next value of generator `uid`.
649 """
--> 650 return six.next(_SHARED_SEQUENCES[uid])
651
652
~/jupyter/Deep-image-matching/modules/modules_custom_callbacks.py in generator(input_csv_path, top_triplets, batch_size, img_height, img_width, channels, imagesDir, batches_per_epoch, epochs_per_triplets, len_features, augmentation_flag, rotation_max)
152 for i in range(batch_size):
153 # Extract query image
--> 154 img = image.load_img(imagesDir+"/"+ls_query_batch[i], target_size=(img_height, img_width))
155 img = image.img_to_array(img)
156 batch_query[i] = img/255
IndexError: list index out of range
Any idea why this is happening?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.