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

Failed to run image_generator.py because randint arg is negative number #13

Open
yukkysaito opened this issue May 5, 2017 · 6 comments

Comments

@yukkysaito
Copy link

@leetenki
Failed to run image_generator.py because randint arg is negative number
I got the errors in the image_generator.py .
First:

  File "image_generate.py", line 24, in <module>
    delta_val_scale=0.5
  File "/home/autoware/workspace/chainer_ws/YOLOv2/lib/image_generator.py", line 171, in generate_samples
    tmp_image, bbox = random_overlay_image(sample_image, item, minimum_crop)
  File "/home/autoware/workspace/chainer_ws/YOLOv2/lib/image_generator.py", line 76, in random_overlay_image
    x = int(np.random.randint(src_w-scale_item_w) - shift_item_w)
  File "mtrand.pyx", line 977, in mtrand.RandomState.randint (numpy/random/mtrand/mtrand.c:16117)
ValueError: low >= high

Second:

loading image generator...
loading model...
start training
Traceback (most recent call last):
  File "darknet19_train.py", line 62, in <module>
    delta_val_scale=0.5
  File "/home/autoware/workspace/chainer_ws/YOLOv2/lib/image_generator.py", line 161, in generate_samples
    bg = self.bgs[np.random.randint(len(self.bgs))]
  File "mtrand.pyx", line 977, in mtrand.RandomState.randint (numpy/random/mtrand/mtrand.c:16117)
ValueError: low >= high
@suishii
Copy link

suishii commented May 15, 2017

Do you fix this problem? I meet the same error,but I do not know how to fix it.

@Siii92
Copy link

Siii92 commented May 24, 2017

I meet the same error too. If you fixed the problem, Could you tell me how to fix it?

RuntimeWarning: divide by zero encountered in long_scalars
return box_intersection(a, b) / box_union(a, b)
Traceback (most recent call last):
File "image_generate.py", line 26, in
delta_val_scale=0.5
File "/home/dl-box/YOLOv2-master/image_generator.py", line 172, in generate_samples
tmp_image, bbox = random_overlay_image(sample_image, item, minimum_crop)
File "/home/dl-box/YOLOv2-master/image_generator.py", line 77, in random_overlay_image
x = int(np.random.randint(src_w-scale_item_w) - shift_item_w)
File "mtrand.pyx", line 885, in mtrand.RandomState.randint (numpy/random/mtrand/mtrand.c:7264)
ValueError: low >= high

@yuma116
Copy link

yuma116 commented May 26, 2017

I have same problems. But, I can't fix this code.

@Siii92
Copy link

Siii92 commented May 30, 2017

if src_h <= scale_item_h:
    src_h, scale_item_h = scale_item_h, src_h
sh = src_h - scale_item_h

a = np.random.randint(sh)
y = int(a - shift_item_h)

if src_w <= scale_item_w:
    src_w, scale_item_w = scale_item_w, src_w
sw = src_w - scale_item_w

b = np.random.randint(sw)
x = int(b - shift_item_w)

try it, and tell me the results.

@suishii
Copy link

suishii commented May 30, 2017

I just fix the minimum_crop to a smaller value than before, I chose 0.75 . And the code is gone.

@kuochiyoug
Copy link

kuochiyoug commented Jun 1, 2017

I fixed it by switching random_overlay_image() function to following scripts,

def random_overlay_image(src_image, overlay_image, minimum_crop):
    src_h, src_w = src_image.shape[:2]
    overlay_h, overlay_w = overlay_image.shape[:2]
    shift_item_h, shift_item_w = overlay_h * (1-minimum_crop), overlay_w * (1-minimum_crop)
    scale_item_h, scale_item_w = overlay_h * (minimum_crop*2-1), overlay_w * (minimum_crop*2-1)
    y_max = src_h-scale_item_h
    x_max = src_w-scale_item_w
    if y_max > 0:
        y = int(np.random.randint(src_h-scale_item_h) - shift_item_h)
    else:
        y = int(- shift_item_h)

    if x_max > 0:
        x = int(np.random.randint(src_w-scale_item_w) - shift_item_w)
    else:
        x = int(-shift_item_w)
    image = overlay(src_image, overlay_image, x, y)
    bbox = ((np.maximum(x, 0), np.maximum(y, 0)), (np.minimum(x+overlay_w, src_w-1), np.minimum(y+overlay_h, src_h-1)))

    return image, bbox

Please have a try

adusa1019 pushed a commit to adusa1019/YOLOv2 that referenced this issue Jul 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants