Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run image_retraining always get ‘integer division or modulo by zero’ #2072

Closed
neverPick opened this issue Apr 23, 2016 · 9 comments

Comments

Projects
None yet
8 participants
@neverPick
Copy link

commented Apr 23, 2016

I tried bazel build tensorflow/examples/image_retraining:retrain && \ bazel-bin/tensorflow/examples/image_retraining/retrain \ --image_dir ~/flowers
but get retrain.py", line 257, in get_image_path mod_index = index % len(category_list) ZeroDivisionError: integer division or modulo by zero
I have got some files, like flower.jpg.txt.
why the length of category list could be zero?

@thair116

This comment has been minimized.

Copy link

commented Apr 24, 2016

You probably saw this warning when running: WARNING: Folder has less than 20 images, which may cause issues.

The retrain script randomly assigns images into three sets: 'training', 'testing', and 'validation' in a way that means you may have 0 validation files if you have less than 20 total training images for a particular label. Try adding at least 20 images per label and you should be good.

Here is the comment in tensorflow/tensorflow/examples/image_retraining/retrain.py that explains what is happening:
# This looks a bit magical, but we need to decide whether this file should # go into the training, testing, or validation sets, and we want to keep # existing files in the same set even if more files are subsequently # added. # To do that, we need a stable way of deciding based on just the file name # itself, so we do a hash of that and then use that to generate a # probability value that we use to assign it.

@neverPick

This comment has been minimized.

Copy link
Author

commented Apr 24, 2016

thanks for ur answer,I just fixed it by set a constant value when it get zero.and I got the final pb file and test will.

@neverPick neverPick closed this Apr 24, 2016

@hrishiwaikar

This comment has been minimized.

Copy link

commented Sep 14, 2016

After step 0 of finding train accuracy and cross entropy , i am getting error:
CRITICAL :tensorflow : category has no images - validation.
.
.
.
ZeroDivisionError: integer division or modulo by zero

I have two class folders : darth vader = 60 images of darth vader and darth maul =60 images.
Kindly suggest solution

@ratajczak

This comment has been minimized.

Copy link

commented Nov 8, 2016

I had the same issue, I resolved it by increasing the number of images.
I was experiencing it with 31 images per label, it disappeared after increasing this number to over 40 per label

@hrishiwaikar

This comment has been minimized.

Copy link

commented Nov 9, 2016

Thanks , I will check this out

On 8 November 2016 at 06:40, Pawel Ratajczak notifications@github.com
wrote:

I had the same issue, I resolved it by increasing number of images.
I was experiencing it with 31 images per label, it disappeared after
increasing this number to over 40 per label


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#2072 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AL-XBxa_RBSsnM0Dq-U0qDCsY_olgv0tks5q8InigaJpZM4IOLfz
.

@fenderrex

This comment has been minimized.

Copy link

commented Apr 28, 2017

so i have about 30 in each folder (not the same number in each). all category look similar. works fine. add to more categorys and i end up here... i fear overriding this if i can photos are hard to find for me...

@mateuyabar

This comment has been minimized.

Copy link

commented Jan 31, 2018

Why not ensuring that there is at least an image in validation? At least it does not crash.
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:
@AndroPlus

This comment has been minimized.

Copy link

commented May 21, 2018

it worked.. i increased image sizes above 25..

@eyildiz-ugoe

This comment has been minimized.

Copy link

commented Jan 16, 2019

For those who have more than 50 images per class and still get the error: The code only works with .jpg files, you need to add 'png' to the list of extensions in 'retrain.py'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.