CRITICAL:tensorflow:Label 51 has no images in the category validation.

最近用tensorflow训练图片分类器tfClassifier中的retrain_new.py进行迁移训练,几年前训练过模型,没问题的,但是这次出问题了,然后解决了,详情如下

2019-02-26 17:47:12.770480: Step 0: Train accuracy = 15.0%
2019-02-26 17:47:12.770480: Step 0: Cross entropy = 3.931970
CRITICAL:tensorflow:Label 51 has no images in the category validation.
CRITICAL:tensorflow:Label 51 has no images in the category validation.
Traceback (most recent call last):
File “retrain_new.py”, line 1019, in
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
File “D:\TensorFlow\Python36\lib\site-packages\tensorflow\python\platform\app.py”, line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File “retrain_new.py”, line 844, in main
bottleneck_tensor))
File “retrain_new.py”, line 485, in get_random_cached_bottlenecks
bottleneck_tensor)
File “retrain_new.py”, line 393, in get_or_create_bottleneck
bottleneck_dir, category)
File “retrain_new.py”, line 248, in get_bottleneck_path
category) + ‘.txt’
File “retrain_new.py”, line 224, in get_image_path
mod_index = index % len(category_list)
ZeroDivisionError: integer division or modulo by zero
网络上给出的解决办法:
https://stackoverflow.com/questions/38175673/critical-tensorflowcategory-has-no-images-validation/38227368
要么修改代码如下:

I’ve modified retrain.py to ensure that at least there is an image in validation (line 201*)

if len(validation_images) == 0:
validation_images.append(base_name)
elif percentage_hash < validation_percentage: (*) Line number may change in future releases. Look at the comments. 要么增加数据集,比如51这个目录地下图片数量可能少于30了,增加到超过30应该就可以了。 试试看哪个方法能够解决你的问题呢?我用的后者。