LabelImg imgSize array includes 0
(One of the images that wasn't working)
I'm using labelImg (https://github.com/tzutalin/labelImg) to annotate images of 2 classes. I have approximately 2000 images, everything works fine until image 681 and all images after, where I get this error:
Traceback (most recent call last):
File "labelImg.py", line 1291, in saveFile
self._saveFile(savedPath)
File "labelImg.py", line 1320, in _saveFile
if annotationFilePath and self.saveLabels(annotationFilePath):
File "labelImg.py", line 808, in saveLabels
self.lineColor.getRgb(), self.fillColor.getRgb())
File "/Users/Mohammed/pythonFiles/100DaysofMLCode/100DaysofMLCode/darkflow-master/labelImg-master/libs/labelFile.py", line 83, in saveYoloFormat
writer.save(targetFile=filename, classList=classList)
File "/Users/Mohammed/pythonFiles/100DaysofMLCode/100DaysofMLCode/darkflow-master/labelImg-master/libs/yolo_io.py", line 70, in save
classIndex, xcen, ycen, w, h = self.BndBox2YoloLine(box, classList)
File "/Users/Mohammed/pythonFiles/100DaysofMLCode/100DaysofMLCode/darkflow-master/labelImg-master/libs/yolo_io.py", line 37, in BndBox2YoloLine
xcen = float((xmin + xmax)) / 2 / self.imgSize[1]
ZeroDivisionError: float division by zero
Abort trap: 6
Looking at this error I went to the file libs/yolo_io.py, and made it print the imgSize, I receive arrays such as [0,0,3]. But I don't know how to fix it as my images seem to have normal sizes.
(I've also commented on the same error on https://github.com/tzutalin/labelImg/issues/386)
Here's the file where the error occurs:
#!/usr/bin/env python
# -*- coding: utf8 -*-
import sys
import os
from xml.etree import ElementTree
from xml.etree.ElementTree import Element, SubElement
from lxml import etree
import codecs
from libs.constants import DEFAULT_ENCODING
TXT_EXT = '.txt'
ENCODE_METHOD = DEFAULT_ENCODING
class YOLOWriter:
def __init__(self, foldername, filename, imgSize, databaseSrc='Unknown', localImgPath=None):
self.foldername = foldername
self.filename = filename
self.databaseSrc = databaseSrc
self.imgSize = imgSize # THIS LINE
self.boxlist =
self.localImgPath = localImgPath
self.verified = False
def addBndBox(self, xmin, ymin, xmax, ymax, name, difficult):
bndbox = {'xmin': xmin, 'ymin': ymin, 'xmax': xmax, 'ymax': ymax}
bndbox['name'] = name
bndbox['difficult'] = difficult
self.boxlist.append(bndbox)
def BndBox2YoloLine(self, box, classList=):
xmin = box['xmin']
xmax = box['xmax']
ymin = box['ymin']
ymax = box['ymax']
xcen = float((xmin + xmax)) / 2 / self.imgSize[1] #THIS LINE
ycen = float((ymin + ymax)) / 2 / self.imgSize[0]
w = float((xmax - xmin)) / self.imgSize[1]
h = float((ymax - ymin)) / self.imgSize[0]
# PR387
boxName = box['name']
if boxName not in classList:
classList.append(boxName)
classIndex = classList.index(boxName)
return classIndex, xcen, ycen, w, h
def save(self, classList=, targetFile=None):
out_file = None #Update yolo .txt
out_class_file = None #Update class list .txt
if targetFile is None:
out_file = open(
self.filename + TXT_EXT, 'w', encoding=ENCODE_METHOD)
classesFile = os.path.join(os.path.dirname(os.path.abspath(self.filename)), "classes.txt")
out_class_file = open(classesFile, 'w')
else:
out_file = codecs.open(targetFile, 'w', encoding=ENCODE_METHOD)
classesFile = os.path.join(os.path.dirname(os.path.abspath(targetFile)), "classes.txt")
out_class_file = open(classesFile, 'w')
for box in self.boxlist:
classIndex, xcen, ycen, w, h = self.BndBox2YoloLine(box, classList)
# print (classIndex, xcen, ycen, w, h)
out_file.write("%d %.6f %.6f %.6f %.6fn" % (classIndex, xcen, ycen, w, h))
# print (classList)
# print (out_class_file)
for c in classList:
out_class_file.write(c+'n')
print(self.imgSize)
out_class_file.close()
out_file.close()
class YoloReader:
def __init__(self, filepath, image, classListPath=None):
# shapes type:
# [labbel, [(x1,y1), (x2,y2), (x3,y3), (x4,y4)], color, color, difficult]
self.shapes =
self.filepath = filepath
if classListPath is None:
dir_path = os.path.dirname(os.path.realpath(self.filepath))
self.classListPath = os.path.join(dir_path, "classes.txt")
else:
self.classListPath = classListPath
# print (filepath, self.classListPath)
classesFile = open(self.classListPath, 'r')
self.classes = classesFile.read().strip('n').split('n')
# print (self.classes)
imgSize = [image.height(), image.width(),
1 if image.isGrayscale() else 3]
self.imgSize = imgSize
self.verified = False
# try:
self.parseYoloFormat()
# except:
# pass
def getShapes(self):
return self.shapes
def addShape(self, label, xmin, ymin, xmax, ymax, difficult):
points = [(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax)]
self.shapes.append((label, points, None, None, difficult))
def yoloLine2Shape(self, classIndex, xcen, ycen, w, h):
label = self.classes[int(classIndex)]
xmin = max(float(xcen) - float(w) / 2, 0)
xmax = min(float(xcen) + float(w) / 2, 1)
ymin = max(float(ycen) - float(h) / 2, 0)
ymax = min(float(ycen) + float(h) / 2, 1)
xmin = int(self.imgSize[1] * xmin)
xmax = int(self.imgSize[1] * xmax)
ymin = int(self.imgSize[0] * ymin)
ymax = int(self.imgSize[0] * ymax)
return label, xmin, ymin, xmax, ymax
def parseYoloFormat(self):
bndBoxFile = open(self.filepath, 'r')
for bndBox in bndBoxFile:
classIndex, xcen, ycen, w, h = bndBox.split(' ')
label, xmin, ymin, xmax, ymax = self.yoloLine2Shape(classIndex, xcen, ycen, w, h)
# Caveat: difficult flag is discarded when saved as yolo format.
self.addShape(label, xmin, ymin, xmax, ymax, False)
python labelimg
|
show 3 more comments
(One of the images that wasn't working)
I'm using labelImg (https://github.com/tzutalin/labelImg) to annotate images of 2 classes. I have approximately 2000 images, everything works fine until image 681 and all images after, where I get this error:
Traceback (most recent call last):
File "labelImg.py", line 1291, in saveFile
self._saveFile(savedPath)
File "labelImg.py", line 1320, in _saveFile
if annotationFilePath and self.saveLabels(annotationFilePath):
File "labelImg.py", line 808, in saveLabels
self.lineColor.getRgb(), self.fillColor.getRgb())
File "/Users/Mohammed/pythonFiles/100DaysofMLCode/100DaysofMLCode/darkflow-master/labelImg-master/libs/labelFile.py", line 83, in saveYoloFormat
writer.save(targetFile=filename, classList=classList)
File "/Users/Mohammed/pythonFiles/100DaysofMLCode/100DaysofMLCode/darkflow-master/labelImg-master/libs/yolo_io.py", line 70, in save
classIndex, xcen, ycen, w, h = self.BndBox2YoloLine(box, classList)
File "/Users/Mohammed/pythonFiles/100DaysofMLCode/100DaysofMLCode/darkflow-master/labelImg-master/libs/yolo_io.py", line 37, in BndBox2YoloLine
xcen = float((xmin + xmax)) / 2 / self.imgSize[1]
ZeroDivisionError: float division by zero
Abort trap: 6
Looking at this error I went to the file libs/yolo_io.py, and made it print the imgSize, I receive arrays such as [0,0,3]. But I don't know how to fix it as my images seem to have normal sizes.
(I've also commented on the same error on https://github.com/tzutalin/labelImg/issues/386)
Here's the file where the error occurs:
#!/usr/bin/env python
# -*- coding: utf8 -*-
import sys
import os
from xml.etree import ElementTree
from xml.etree.ElementTree import Element, SubElement
from lxml import etree
import codecs
from libs.constants import DEFAULT_ENCODING
TXT_EXT = '.txt'
ENCODE_METHOD = DEFAULT_ENCODING
class YOLOWriter:
def __init__(self, foldername, filename, imgSize, databaseSrc='Unknown', localImgPath=None):
self.foldername = foldername
self.filename = filename
self.databaseSrc = databaseSrc
self.imgSize = imgSize # THIS LINE
self.boxlist =
self.localImgPath = localImgPath
self.verified = False
def addBndBox(self, xmin, ymin, xmax, ymax, name, difficult):
bndbox = {'xmin': xmin, 'ymin': ymin, 'xmax': xmax, 'ymax': ymax}
bndbox['name'] = name
bndbox['difficult'] = difficult
self.boxlist.append(bndbox)
def BndBox2YoloLine(self, box, classList=):
xmin = box['xmin']
xmax = box['xmax']
ymin = box['ymin']
ymax = box['ymax']
xcen = float((xmin + xmax)) / 2 / self.imgSize[1] #THIS LINE
ycen = float((ymin + ymax)) / 2 / self.imgSize[0]
w = float((xmax - xmin)) / self.imgSize[1]
h = float((ymax - ymin)) / self.imgSize[0]
# PR387
boxName = box['name']
if boxName not in classList:
classList.append(boxName)
classIndex = classList.index(boxName)
return classIndex, xcen, ycen, w, h
def save(self, classList=, targetFile=None):
out_file = None #Update yolo .txt
out_class_file = None #Update class list .txt
if targetFile is None:
out_file = open(
self.filename + TXT_EXT, 'w', encoding=ENCODE_METHOD)
classesFile = os.path.join(os.path.dirname(os.path.abspath(self.filename)), "classes.txt")
out_class_file = open(classesFile, 'w')
else:
out_file = codecs.open(targetFile, 'w', encoding=ENCODE_METHOD)
classesFile = os.path.join(os.path.dirname(os.path.abspath(targetFile)), "classes.txt")
out_class_file = open(classesFile, 'w')
for box in self.boxlist:
classIndex, xcen, ycen, w, h = self.BndBox2YoloLine(box, classList)
# print (classIndex, xcen, ycen, w, h)
out_file.write("%d %.6f %.6f %.6f %.6fn" % (classIndex, xcen, ycen, w, h))
# print (classList)
# print (out_class_file)
for c in classList:
out_class_file.write(c+'n')
print(self.imgSize)
out_class_file.close()
out_file.close()
class YoloReader:
def __init__(self, filepath, image, classListPath=None):
# shapes type:
# [labbel, [(x1,y1), (x2,y2), (x3,y3), (x4,y4)], color, color, difficult]
self.shapes =
self.filepath = filepath
if classListPath is None:
dir_path = os.path.dirname(os.path.realpath(self.filepath))
self.classListPath = os.path.join(dir_path, "classes.txt")
else:
self.classListPath = classListPath
# print (filepath, self.classListPath)
classesFile = open(self.classListPath, 'r')
self.classes = classesFile.read().strip('n').split('n')
# print (self.classes)
imgSize = [image.height(), image.width(),
1 if image.isGrayscale() else 3]
self.imgSize = imgSize
self.verified = False
# try:
self.parseYoloFormat()
# except:
# pass
def getShapes(self):
return self.shapes
def addShape(self, label, xmin, ymin, xmax, ymax, difficult):
points = [(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax)]
self.shapes.append((label, points, None, None, difficult))
def yoloLine2Shape(self, classIndex, xcen, ycen, w, h):
label = self.classes[int(classIndex)]
xmin = max(float(xcen) - float(w) / 2, 0)
xmax = min(float(xcen) + float(w) / 2, 1)
ymin = max(float(ycen) - float(h) / 2, 0)
ymax = min(float(ycen) + float(h) / 2, 1)
xmin = int(self.imgSize[1] * xmin)
xmax = int(self.imgSize[1] * xmax)
ymin = int(self.imgSize[0] * ymin)
ymax = int(self.imgSize[0] * ymax)
return label, xmin, ymin, xmax, ymax
def parseYoloFormat(self):
bndBoxFile = open(self.filepath, 'r')
for bndBox in bndBoxFile:
classIndex, xcen, ycen, w, h = bndBox.split(' ')
label, xmin, ymin, xmax, ymax = self.yoloLine2Shape(classIndex, xcen, ycen, w, h)
# Caveat: difficult flag is discarded when saved as yolo format.
self.addShape(label, xmin, ymin, xmax, ymax, False)
python labelimg
Check if self.imgSize[1] is zero. Either it is not being set properly or it's actually zero. Check if image dimensions are correct.
– Vishnudev
Nov 18 '18 at 8:36
self.imgSize[1] is 0, since the array is [0,0,3].
– Mohammed Balfakeih
Nov 18 '18 at 8:57
Handle the division by zero error then
– Vishnudev
Nov 18 '18 at 9:26
try: #your code except ZeroDivisionError: print("Can't have zero as image size")
– Vishnudev
Nov 18 '18 at 9:28
The variable xcen is necessary later on, so I can't do that
– Mohammed Balfakeih
Nov 18 '18 at 9:56
|
show 3 more comments
(One of the images that wasn't working)
I'm using labelImg (https://github.com/tzutalin/labelImg) to annotate images of 2 classes. I have approximately 2000 images, everything works fine until image 681 and all images after, where I get this error:
Traceback (most recent call last):
File "labelImg.py", line 1291, in saveFile
self._saveFile(savedPath)
File "labelImg.py", line 1320, in _saveFile
if annotationFilePath and self.saveLabels(annotationFilePath):
File "labelImg.py", line 808, in saveLabels
self.lineColor.getRgb(), self.fillColor.getRgb())
File "/Users/Mohammed/pythonFiles/100DaysofMLCode/100DaysofMLCode/darkflow-master/labelImg-master/libs/labelFile.py", line 83, in saveYoloFormat
writer.save(targetFile=filename, classList=classList)
File "/Users/Mohammed/pythonFiles/100DaysofMLCode/100DaysofMLCode/darkflow-master/labelImg-master/libs/yolo_io.py", line 70, in save
classIndex, xcen, ycen, w, h = self.BndBox2YoloLine(box, classList)
File "/Users/Mohammed/pythonFiles/100DaysofMLCode/100DaysofMLCode/darkflow-master/labelImg-master/libs/yolo_io.py", line 37, in BndBox2YoloLine
xcen = float((xmin + xmax)) / 2 / self.imgSize[1]
ZeroDivisionError: float division by zero
Abort trap: 6
Looking at this error I went to the file libs/yolo_io.py, and made it print the imgSize, I receive arrays such as [0,0,3]. But I don't know how to fix it as my images seem to have normal sizes.
(I've also commented on the same error on https://github.com/tzutalin/labelImg/issues/386)
Here's the file where the error occurs:
#!/usr/bin/env python
# -*- coding: utf8 -*-
import sys
import os
from xml.etree import ElementTree
from xml.etree.ElementTree import Element, SubElement
from lxml import etree
import codecs
from libs.constants import DEFAULT_ENCODING
TXT_EXT = '.txt'
ENCODE_METHOD = DEFAULT_ENCODING
class YOLOWriter:
def __init__(self, foldername, filename, imgSize, databaseSrc='Unknown', localImgPath=None):
self.foldername = foldername
self.filename = filename
self.databaseSrc = databaseSrc
self.imgSize = imgSize # THIS LINE
self.boxlist =
self.localImgPath = localImgPath
self.verified = False
def addBndBox(self, xmin, ymin, xmax, ymax, name, difficult):
bndbox = {'xmin': xmin, 'ymin': ymin, 'xmax': xmax, 'ymax': ymax}
bndbox['name'] = name
bndbox['difficult'] = difficult
self.boxlist.append(bndbox)
def BndBox2YoloLine(self, box, classList=):
xmin = box['xmin']
xmax = box['xmax']
ymin = box['ymin']
ymax = box['ymax']
xcen = float((xmin + xmax)) / 2 / self.imgSize[1] #THIS LINE
ycen = float((ymin + ymax)) / 2 / self.imgSize[0]
w = float((xmax - xmin)) / self.imgSize[1]
h = float((ymax - ymin)) / self.imgSize[0]
# PR387
boxName = box['name']
if boxName not in classList:
classList.append(boxName)
classIndex = classList.index(boxName)
return classIndex, xcen, ycen, w, h
def save(self, classList=, targetFile=None):
out_file = None #Update yolo .txt
out_class_file = None #Update class list .txt
if targetFile is None:
out_file = open(
self.filename + TXT_EXT, 'w', encoding=ENCODE_METHOD)
classesFile = os.path.join(os.path.dirname(os.path.abspath(self.filename)), "classes.txt")
out_class_file = open(classesFile, 'w')
else:
out_file = codecs.open(targetFile, 'w', encoding=ENCODE_METHOD)
classesFile = os.path.join(os.path.dirname(os.path.abspath(targetFile)), "classes.txt")
out_class_file = open(classesFile, 'w')
for box in self.boxlist:
classIndex, xcen, ycen, w, h = self.BndBox2YoloLine(box, classList)
# print (classIndex, xcen, ycen, w, h)
out_file.write("%d %.6f %.6f %.6f %.6fn" % (classIndex, xcen, ycen, w, h))
# print (classList)
# print (out_class_file)
for c in classList:
out_class_file.write(c+'n')
print(self.imgSize)
out_class_file.close()
out_file.close()
class YoloReader:
def __init__(self, filepath, image, classListPath=None):
# shapes type:
# [labbel, [(x1,y1), (x2,y2), (x3,y3), (x4,y4)], color, color, difficult]
self.shapes =
self.filepath = filepath
if classListPath is None:
dir_path = os.path.dirname(os.path.realpath(self.filepath))
self.classListPath = os.path.join(dir_path, "classes.txt")
else:
self.classListPath = classListPath
# print (filepath, self.classListPath)
classesFile = open(self.classListPath, 'r')
self.classes = classesFile.read().strip('n').split('n')
# print (self.classes)
imgSize = [image.height(), image.width(),
1 if image.isGrayscale() else 3]
self.imgSize = imgSize
self.verified = False
# try:
self.parseYoloFormat()
# except:
# pass
def getShapes(self):
return self.shapes
def addShape(self, label, xmin, ymin, xmax, ymax, difficult):
points = [(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax)]
self.shapes.append((label, points, None, None, difficult))
def yoloLine2Shape(self, classIndex, xcen, ycen, w, h):
label = self.classes[int(classIndex)]
xmin = max(float(xcen) - float(w) / 2, 0)
xmax = min(float(xcen) + float(w) / 2, 1)
ymin = max(float(ycen) - float(h) / 2, 0)
ymax = min(float(ycen) + float(h) / 2, 1)
xmin = int(self.imgSize[1] * xmin)
xmax = int(self.imgSize[1] * xmax)
ymin = int(self.imgSize[0] * ymin)
ymax = int(self.imgSize[0] * ymax)
return label, xmin, ymin, xmax, ymax
def parseYoloFormat(self):
bndBoxFile = open(self.filepath, 'r')
for bndBox in bndBoxFile:
classIndex, xcen, ycen, w, h = bndBox.split(' ')
label, xmin, ymin, xmax, ymax = self.yoloLine2Shape(classIndex, xcen, ycen, w, h)
# Caveat: difficult flag is discarded when saved as yolo format.
self.addShape(label, xmin, ymin, xmax, ymax, False)
python labelimg
(One of the images that wasn't working)
I'm using labelImg (https://github.com/tzutalin/labelImg) to annotate images of 2 classes. I have approximately 2000 images, everything works fine until image 681 and all images after, where I get this error:
Traceback (most recent call last):
File "labelImg.py", line 1291, in saveFile
self._saveFile(savedPath)
File "labelImg.py", line 1320, in _saveFile
if annotationFilePath and self.saveLabels(annotationFilePath):
File "labelImg.py", line 808, in saveLabels
self.lineColor.getRgb(), self.fillColor.getRgb())
File "/Users/Mohammed/pythonFiles/100DaysofMLCode/100DaysofMLCode/darkflow-master/labelImg-master/libs/labelFile.py", line 83, in saveYoloFormat
writer.save(targetFile=filename, classList=classList)
File "/Users/Mohammed/pythonFiles/100DaysofMLCode/100DaysofMLCode/darkflow-master/labelImg-master/libs/yolo_io.py", line 70, in save
classIndex, xcen, ycen, w, h = self.BndBox2YoloLine(box, classList)
File "/Users/Mohammed/pythonFiles/100DaysofMLCode/100DaysofMLCode/darkflow-master/labelImg-master/libs/yolo_io.py", line 37, in BndBox2YoloLine
xcen = float((xmin + xmax)) / 2 / self.imgSize[1]
ZeroDivisionError: float division by zero
Abort trap: 6
Looking at this error I went to the file libs/yolo_io.py, and made it print the imgSize, I receive arrays such as [0,0,3]. But I don't know how to fix it as my images seem to have normal sizes.
(I've also commented on the same error on https://github.com/tzutalin/labelImg/issues/386)
Here's the file where the error occurs:
#!/usr/bin/env python
# -*- coding: utf8 -*-
import sys
import os
from xml.etree import ElementTree
from xml.etree.ElementTree import Element, SubElement
from lxml import etree
import codecs
from libs.constants import DEFAULT_ENCODING
TXT_EXT = '.txt'
ENCODE_METHOD = DEFAULT_ENCODING
class YOLOWriter:
def __init__(self, foldername, filename, imgSize, databaseSrc='Unknown', localImgPath=None):
self.foldername = foldername
self.filename = filename
self.databaseSrc = databaseSrc
self.imgSize = imgSize # THIS LINE
self.boxlist =
self.localImgPath = localImgPath
self.verified = False
def addBndBox(self, xmin, ymin, xmax, ymax, name, difficult):
bndbox = {'xmin': xmin, 'ymin': ymin, 'xmax': xmax, 'ymax': ymax}
bndbox['name'] = name
bndbox['difficult'] = difficult
self.boxlist.append(bndbox)
def BndBox2YoloLine(self, box, classList=):
xmin = box['xmin']
xmax = box['xmax']
ymin = box['ymin']
ymax = box['ymax']
xcen = float((xmin + xmax)) / 2 / self.imgSize[1] #THIS LINE
ycen = float((ymin + ymax)) / 2 / self.imgSize[0]
w = float((xmax - xmin)) / self.imgSize[1]
h = float((ymax - ymin)) / self.imgSize[0]
# PR387
boxName = box['name']
if boxName not in classList:
classList.append(boxName)
classIndex = classList.index(boxName)
return classIndex, xcen, ycen, w, h
def save(self, classList=, targetFile=None):
out_file = None #Update yolo .txt
out_class_file = None #Update class list .txt
if targetFile is None:
out_file = open(
self.filename + TXT_EXT, 'w', encoding=ENCODE_METHOD)
classesFile = os.path.join(os.path.dirname(os.path.abspath(self.filename)), "classes.txt")
out_class_file = open(classesFile, 'w')
else:
out_file = codecs.open(targetFile, 'w', encoding=ENCODE_METHOD)
classesFile = os.path.join(os.path.dirname(os.path.abspath(targetFile)), "classes.txt")
out_class_file = open(classesFile, 'w')
for box in self.boxlist:
classIndex, xcen, ycen, w, h = self.BndBox2YoloLine(box, classList)
# print (classIndex, xcen, ycen, w, h)
out_file.write("%d %.6f %.6f %.6f %.6fn" % (classIndex, xcen, ycen, w, h))
# print (classList)
# print (out_class_file)
for c in classList:
out_class_file.write(c+'n')
print(self.imgSize)
out_class_file.close()
out_file.close()
class YoloReader:
def __init__(self, filepath, image, classListPath=None):
# shapes type:
# [labbel, [(x1,y1), (x2,y2), (x3,y3), (x4,y4)], color, color, difficult]
self.shapes =
self.filepath = filepath
if classListPath is None:
dir_path = os.path.dirname(os.path.realpath(self.filepath))
self.classListPath = os.path.join(dir_path, "classes.txt")
else:
self.classListPath = classListPath
# print (filepath, self.classListPath)
classesFile = open(self.classListPath, 'r')
self.classes = classesFile.read().strip('n').split('n')
# print (self.classes)
imgSize = [image.height(), image.width(),
1 if image.isGrayscale() else 3]
self.imgSize = imgSize
self.verified = False
# try:
self.parseYoloFormat()
# except:
# pass
def getShapes(self):
return self.shapes
def addShape(self, label, xmin, ymin, xmax, ymax, difficult):
points = [(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax)]
self.shapes.append((label, points, None, None, difficult))
def yoloLine2Shape(self, classIndex, xcen, ycen, w, h):
label = self.classes[int(classIndex)]
xmin = max(float(xcen) - float(w) / 2, 0)
xmax = min(float(xcen) + float(w) / 2, 1)
ymin = max(float(ycen) - float(h) / 2, 0)
ymax = min(float(ycen) + float(h) / 2, 1)
xmin = int(self.imgSize[1] * xmin)
xmax = int(self.imgSize[1] * xmax)
ymin = int(self.imgSize[0] * ymin)
ymax = int(self.imgSize[0] * ymax)
return label, xmin, ymin, xmax, ymax
def parseYoloFormat(self):
bndBoxFile = open(self.filepath, 'r')
for bndBox in bndBoxFile:
classIndex, xcen, ycen, w, h = bndBox.split(' ')
label, xmin, ymin, xmax, ymax = self.yoloLine2Shape(classIndex, xcen, ycen, w, h)
# Caveat: difficult flag is discarded when saved as yolo format.
self.addShape(label, xmin, ymin, xmax, ymax, False)
python labelimg
python labelimg
edited Nov 20 '18 at 18:05
Mohammed Balfakeih
asked Nov 18 '18 at 8:32
Mohammed BalfakeihMohammed Balfakeih
136
136
Check if self.imgSize[1] is zero. Either it is not being set properly or it's actually zero. Check if image dimensions are correct.
– Vishnudev
Nov 18 '18 at 8:36
self.imgSize[1] is 0, since the array is [0,0,3].
– Mohammed Balfakeih
Nov 18 '18 at 8:57
Handle the division by zero error then
– Vishnudev
Nov 18 '18 at 9:26
try: #your code except ZeroDivisionError: print("Can't have zero as image size")
– Vishnudev
Nov 18 '18 at 9:28
The variable xcen is necessary later on, so I can't do that
– Mohammed Balfakeih
Nov 18 '18 at 9:56
|
show 3 more comments
Check if self.imgSize[1] is zero. Either it is not being set properly or it's actually zero. Check if image dimensions are correct.
– Vishnudev
Nov 18 '18 at 8:36
self.imgSize[1] is 0, since the array is [0,0,3].
– Mohammed Balfakeih
Nov 18 '18 at 8:57
Handle the division by zero error then
– Vishnudev
Nov 18 '18 at 9:26
try: #your code except ZeroDivisionError: print("Can't have zero as image size")
– Vishnudev
Nov 18 '18 at 9:28
The variable xcen is necessary later on, so I can't do that
– Mohammed Balfakeih
Nov 18 '18 at 9:56
Check if self.imgSize[1] is zero. Either it is not being set properly or it's actually zero. Check if image dimensions are correct.
– Vishnudev
Nov 18 '18 at 8:36
Check if self.imgSize[1] is zero. Either it is not being set properly or it's actually zero. Check if image dimensions are correct.
– Vishnudev
Nov 18 '18 at 8:36
self.imgSize[1] is 0, since the array is [0,0,3].
– Mohammed Balfakeih
Nov 18 '18 at 8:57
self.imgSize[1] is 0, since the array is [0,0,3].
– Mohammed Balfakeih
Nov 18 '18 at 8:57
Handle the division by zero error then
– Vishnudev
Nov 18 '18 at 9:26
Handle the division by zero error then
– Vishnudev
Nov 18 '18 at 9:26
try: #your code except ZeroDivisionError: print("Can't have zero as image size")
– Vishnudev
Nov 18 '18 at 9:28
try: #your code except ZeroDivisionError: print("Can't have zero as image size")
– Vishnudev
Nov 18 '18 at 9:28
The variable xcen is necessary later on, so I can't do that
– Mohammed Balfakeih
Nov 18 '18 at 9:56
The variable xcen is necessary later on, so I can't do that
– Mohammed Balfakeih
Nov 18 '18 at 9:56
|
show 3 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53359112%2flabelimg-imgsize-array-includes-0%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53359112%2flabelimg-imgsize-array-includes-0%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Check if self.imgSize[1] is zero. Either it is not being set properly or it's actually zero. Check if image dimensions are correct.
– Vishnudev
Nov 18 '18 at 8:36
self.imgSize[1] is 0, since the array is [0,0,3].
– Mohammed Balfakeih
Nov 18 '18 at 8:57
Handle the division by zero error then
– Vishnudev
Nov 18 '18 at 9:26
try: #your code except ZeroDivisionError: print("Can't have zero as image size")
– Vishnudev
Nov 18 '18 at 9:28
The variable xcen is necessary later on, so I can't do that
– Mohammed Balfakeih
Nov 18 '18 at 9:56