I'm trying to run CUHK03 Person Re-ID script by Ning-Ding ( Implementation of Ahmed et. al.'s paper using Keras) see https://github.com/Ning-Ding/Implementation-CVPR2015-CNN-for-ReID
Error text reads as follows:
TypeError Traceback (most recent call last)
in ()
----> 1 main("E:\DL\cuhk-03.h5")
in main(dataset_path)
17 model = generate_model()
18 model = compile_model(model)
---> 19 train(model, dataset_path)
20
21 def train(model,
in train(model, h5_path, weights_name, train_num, one_epoch, epoch_num, flag_random, random_pattern, flag_train, flag_val, which_val_data, nb_val_samples)
39 rand_x = np.random.rand()
40 flag_train = random_pattern(rand_x)
---> 41 model.fit_generator(Data_Generator.flow(f,flag = flag_train),one_epoch,epoch_num,validation_data=Data_Generator.flow(f,train_or_validation=which_val_data,flag=flag_val),nb_val_samples=nb_val_samples)
42 Rank1s.append(round(cmc(model)[0],2))
43 print (Rank1s)
~\Anaconda3\lib\site-packages\keras\legacy\interfaces.py in wrapper(*args, **kwargs)
89 warnings.warn('Update your ' + object_name + 90 ' call to the Keras 2 API: ' + signature, stacklevel=2)
---> 91 return func(*args, **kwargs)
92 wrapper._original_function = func
93 return wrapper
~\Anaconda3\lib\site-packages\keras\engine\training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
2023 epoch = initial_epoch
2024
-> 2025 do_validation = bool(validation_data)
2026 self._make_train_function()
2027 if do_validation:
TypeError: 'float' object cannot be interpreted as an integer
I am using Jupyter Notebook in Anaconda on Windows 10(x86). Keras version 2.1.3 Python version 3.6.3 Tensorflow backend (1.4.0)
Ok, so that validation_data
is a generator returned by
Data_Generator.flow(f,train_or_validation=which_val_data,flag=flag_val)
When do_validation = bool(validation_data)
is executed, calling bool on an object will call nonzero
or len
if any of them is defined. In this case, Sequence
implements len
so it checks if len(Sequence) == 0
. Your issue is that len
returns a float
(which is an error) so when it tries to convert it in a bool
, it fails.
Assert that len
returns an int
.
Credit goes to Dref360 at https://www.bountysource.com/issues/54744813-fit_generator-throws-error-on-validation-data-being-float-data-type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With