gpt4 book ai didi

deep-learning - Keras fit_generator 验证数据类型错误 : 'float' object cannot be interpreted as an integer

转载 作者:行者123 更新时间:2023-12-04 23:37:38 24 4
gpt4 key购买 nike

我正在尝试通过 Ning-Ding 运行 CUHK03 Person Re-ID 脚本(使用 Keras 实现 Ahmed 等人的论文)
https://github.com/Ning-Ding/Implementation-CVPR2015-CNN-for-ReID

错误文本如下:

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

我在 Windows 10(x86) 上的 Anaconda 中使用 Jupyter Notebook。
Keras 2.1.3 版
Python 版本 3.6.3
Tensorflow 后端 (1.4.0)

最佳答案

好的,这样 validation_data是一个由返回的生成器

Data_Generator.flow(f,train_or_validation=which_val_data,flag=flag_val)

do_validation = bool(validation_data)被执行,对对象调用 bool 将调用 nonzerolen如果定义了其中任何一个。在这种情况下, Sequence工具 len所以它会检查 if len(Sequence) == 0 .您的问题是 len返回 float (这是一个错误)所以当它试图在 bool 中转换它时, 它失败。

断言 len返回 int .

归功于 https://www.bountysource.com/issues/54744813-fit_generator-throws-error-on-validation-data-being-float-data-type 的 Dref360

关于deep-learning - Keras fit_generator 验证数据类型错误 : 'float' object cannot be interpreted as an integer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48754203/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com