Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

prevent duration = 0.0 and divding by zero #284

Merged
merged 3 commits into from
Jun 16, 2017

Conversation

sitifukujin
Copy link

It is small bug. On my windows, it occurs dividing zero 100%. It might occur on linux.

@yuyu2172
Copy link
Member

LGTM
Thank you for your contribution!

@yuyu2172 yuyu2172 added this to the v0.6 milestone Jun 16, 2017
@yuyu2172 yuyu2172 added the bug label Jun 16, 2017
@Hakuyume
Copy link
Member

How about showing inf for speed when duration is zero?

@sitifukujin
Copy link
Author

Hello again, Hakuyume-san,
Would you want to see stack trace?

Downloading from http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar...
Traceback (most recent call last):
  File "D:\DeepLearning\Github\sitifukujin_chainercv\examples\detection\visualize_models.py", line 53, in <module>
    main()
  File "D:\DeepLearning\Github\sitifukujin_chainercv\examples\detection\visualize_models.py", line 18, in main
    dataset = VOCDetectionDataset(year='2007', split='test')
  File "D:\DeepLearning\Github\sitifukujin_chainercv\chainercv\datasets\voc\voc_detection_dataset.py", line 72, in __init__
    data_dir = voc_utils.get_voc(year, split)
  File "D:\DeepLearning\Github\sitifukujin_chainercv\chainercv\datasets\voc\voc_utils.py", line 34, in get_voc
    download_file_path = utils.cached_download(urls[key])
  File "D:\DeepLearning\Github\sitifukujin_chainercv\chainercv\utils\download.py", line 72, in cached_download
    request.urlretrieve(url, temp_path, _reporthook)
  File "C:\Anaconda3\lib\urllib\request.py", line 284, in urlretrieve
    reporthook(blocknum, bs, size)
  File "D:\DeepLearning\Github\sitifukujin_chainercv\chainercv\utils\download.py", line 27, in _reporthook
    speed = int(progress_size / (1024 * duration))
ZeroDivisionError: float division by zero
Press any key to continue . . .

@Hakuyume
Copy link
Member

@sitifukujin I think using small value for duration is not a good solution because it shows nonsense speed. How about showing 'inf KB/s' when the duration is zero. User can know that the speed can't be computed now.

progress_size = int(count * block_size)
speed = int(progress_size / (1024 * duration))
if duration > 1e-4:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using try and except to catch ZeroDivisionError. I think this is better because we can remove a magic value 1e-4.

@sitifukujin
Copy link
Author

@Hakuyume
Line this?

Downloading from http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar...

...0, 0.0078125 MB, inf KB/s, 0.0 seconds passed
...0, 0.015625 MB, 59 KB/s, 0.26875853538513184 seconds passed
...0, 0.0234375 MB, 89 KB/s, 0.26875853538513184 seconds passed

@Hakuyume
Copy link
Member

@sitifukujin Yes. I think this output is better. I added a comment. Please check it.

@sitifukujin
Copy link
Author

Please check it again.

Copy link
Member

@Hakuyume Hakuyume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Hakuyume Hakuyume merged commit 673e323 into chainer:master Jun 16, 2017
@sitifukujin
Copy link
Author

Thanks, Yuyu-san and Hakuyume-san. See you.

@sitifukujin sitifukujin deleted the bugfix_duration_zero branch June 16, 2017 08:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants