我正在根据此处的代码重新训练Inception v3网络:https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/#0。我有一组200个标签。每个标签的图像数量在50到15000之间。在重新训练过程中,我遇到了以下错误:
2017-01-08 07:42:09.683263: Step 30: Train accuracy = 6.0%2017-01-08 07:42:09.683384: Step 30: Cross entropy = 6.2971372017-01-08 07:42:09.808175: Step 30: Validation accuracy = 0.0%2017-01-08 07:42:11.083850: Step 40: Train accuracy = 2.0%2017-01-08 07:42:11.083964: Step 40: Cross entropy = 6.296147CRITICAL:tensorflow:Label corset has no images in the category validation.Traceback (most recent call last): File "tensorflow/examples/image_retraining/retrain.py", line 1012, in <module> tf.app.run(main=main, argv=[sys.argv[0]] + unparsed) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 43, in run sys.exit(main(sys.argv[:1] + flags_passthrough)) File "tensorflow/examples/image_retraining/retrain.py", line 839, in main bottleneck_tensor)) File "tensorflow/examples/image_retraining/retrain.py", line 480, in get_random_cached_bottlenecks bottleneck_tensor) File "tensorflow/examples/image_retraining/retrain.py", line 388, in get_or_create_bottleneck bottleneck_dir, category) File "tensorflow/examples/image_retraining/retrain.py", line 245, in get_bottleneck_path category) + '.txt' File "tensorflow/examples/image_retraining/retrain.py", line 221, in get_image_path mod_index = index % len(category_list)ZeroDivisionError: integer division or modulo by zero`
通过在谷歌上搜索,我了解到如果图像少于20张,可能会出现这样的错误。这是因为可能没有足够的图像留作验证。然而,我至少有50张图像。那么,为什么我仍然会遇到这个错误呢?
回答:
我查看了你帖子中教程链接的tensorflow/examples/image_retraining/retrain.py
文件。
运行的代码部分包括在函数create_image_lists(image_dir, testing_percentage, validation_percentage)
中进行的训练/验证拆分。
拆分的默认值是10%,这在FLAGS.validation_percentage
中说明了。
由于你有一些类别的图像少于200张,拆分后验证集中的图像数量会少于20张,这就是你遇到错误的原因。
尝试仅使用图像数量超过200的类别运行代码,看看是否有帮助。如果有效,你可以考虑添加更多图像,或者修改create_image_lists
函数以确保验证集至少有20张图像。