Labelimg: ZeroDivisionError: float division by zero

Created on 2 Nov 2018  路  9Comments  路  Source: tzutalin/labelImg

Img: /home/legolas/darknet/VOCdevkit/VOC2007/JPEGImages/reliao_img_1540548508095.jpg -> Its txt: /home/legolas/darknet/VOCdevkit/VOC2007/JPEGImages/reliao_img_1540548508095.txt
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/labelImg-1.8.0-py2.7.egg/labelImg/labelImg.py", line 1298, in saveFile
else self.saveFileDialog())
File "/usr/local/lib/python2.7/dist-packages/labelImg-1.8.0-py2.7.egg/labelImg/labelImg.py", line 1320, in _saveFile
if annotationFilePath and self.saveLabels(annotationFilePath):
File "/usr/local/lib/python2.7/dist-packages/labelImg-1.8.0-py2.7.egg/labelImg/labelImg.py", line 808, in saveLabels
self.lineColor.getRgb(), self.fillColor.getRgb())
File "/usr/local/lib/python2.7/dist-packages/labelImg-1.8.0-py2.7.egg/libs/labelFile.py", line 83, in saveYoloFormat
writer.save(targetFile=filename, classList=classList)
File "/usr/local/lib/python2.7/dist-packages/labelImg-1.8.0-py2.7.egg/libs/yolo_io.py", line 64, in save
classIndex, xcen, ycen, w, h = self.BndBox2YoloLine(box, classList)
File "/usr/local/lib/python2.7/dist-packages/labelImg-1.8.0-py2.7.egg/libs/yolo_io.py", line 36, in BndBox2YoloLine
xcen = float((xmin + xmax)) / 2 / self.imgSize[1]
ZeroDivisionError: float division by zero

Most helpful comment

this problem was solved by change to PNG image 馃憤in my case

All 9 comments

Please describe what you were trying to do when this error occurred.

Providing the image and label file would also be useful.

I am experiencing this same issue, all images after image 681 (there are about 2500 images) give me this exact error. I am trying to label these images, but when I try to save I recieve this error, with an Abort Trap: 6, at the end of it. I don't think it's anything wrong with the images, as some of these are the exact same pictures as previous ones.

I'm using python 3.6.6

000681
000682
000683
000684
Here are some of the images that weren't working

I had this problem too. In my case it was caused by something in the jpg-file that caused QImage to set dimensions of loaded file to 0,0,3. GIMP could not open the file either, even though some image viewers could. In my case the problem was solved by loading the problematic image into viewer that could open it and saving it again.

I have the same error, when I try to label images,the error is below:
Traceback (most recent call last): File "<string>", line 1298, in saveFile File "<string>", line 1320, in _saveFile File "<string>", line 808, in saveLabels File "Z:\home\darrenl\tmp\labelImg\build-tools\build\labelImg\out00-PYZ.pyz\libs.labelFile", line 83, in saveYoloFormat File "Z:\home\darrenl\tmp\labelImg\build-tools\build\labelImg\out00-PYZ.pyz\libs.yolo_io", line 64, in save File "Z:\home\darrenl\tmp\labelImg\build-tools\build\labelImg\out00-PYZ.pyz\libs.yolo_io", line 36, in BndBox2YoloLine ZeroDivisionError: float division by zero

I cant figure out where the location Z is , and why this error happens.

this problem was solved by change to PNG image 馃憤in my case

i faced the same problem, this happens due to transparency in the some images, i dnt know what kind of transparency is this,......but it can be solved by opening the image with opencv and saving it again, it worked for me.

i wrote this python file :--

import cv2
import os

def loadImages(path = "."):

return [os.path.join(path, f) for f in os.listdir(path) if f.endswith('.jpg')]

filenames = loadImages()
images = []
for file in filenames:
images.append(cv2.imread(file, cv2.IMREAD_UNCHANGED))

num = 0
for image in images:
cv2.imwrite(str(num)+".jpg",image)
num += 1

it will open every file in the directory and save it again!!

My issue was solved by converting the .jpg images to .png images, exactly what @thanh15dt2 mentioned. I did it by following this tutorial: https://www.youtube.com/watch?v=FGr3N3DLGEI

Was this page helpful?
0 / 5 - 0 ratings