glenn-jocher commited on
Commit
6c0e1d9
1 Parent(s): 65f81bf

Update `verify_image_label()` (#3635)

Browse files
Files changed (1) hide show
  1. utils/datasets.py +4 -4
utils/datasets.py CHANGED
@@ -1046,20 +1046,20 @@ def autosplit(path='../coco128', weights=(0.9, 0.1, 0.0), annotated_only=False):
1046
  f.write(str(img) + '\n') # add image to txt file
1047
 
1048
 
1049
- def verify_image_label(params):
1050
  # Verify one image-label pair
1051
- im_file, lb_file, prefix = params
1052
  nm, nf, ne, nc = 0, 0, 0, 0 # number missing, found, empty, corrupt
1053
  try:
1054
  # verify images
1055
  im = Image.open(im_file)
1056
  im.verify() # PIL verify
1057
  shape = exif_size(im) # image size
1058
- segments = [] # instance segments
1059
  assert (shape[0] > 9) & (shape[1] > 9), f'image size {shape} <10 pixels'
1060
  assert im.format.lower() in img_formats, f'invalid image format {im.format}'
1061
 
1062
  # verify labels
 
1063
  if os.path.isfile(lb_file):
1064
  nf = 1 # label found
1065
  with open(lb_file, 'r') as f:
@@ -1084,7 +1084,7 @@ def verify_image_label(params):
1084
  except Exception as e:
1085
  nc = 1
1086
  logging.info(f'{prefix}WARNING: Ignoring corrupted image and/or label {im_file}: {e}')
1087
- return [None] * 4 + [nm, nf, ne, nc]
1088
 
1089
 
1090
  def dataset_stats(path='coco128.yaml', autodownload=False, verbose=False):
 
1046
  f.write(str(img) + '\n') # add image to txt file
1047
 
1048
 
1049
+ def verify_image_label(args):
1050
  # Verify one image-label pair
1051
+ im_file, lb_file, prefix = args
1052
  nm, nf, ne, nc = 0, 0, 0, 0 # number missing, found, empty, corrupt
1053
  try:
1054
  # verify images
1055
  im = Image.open(im_file)
1056
  im.verify() # PIL verify
1057
  shape = exif_size(im) # image size
 
1058
  assert (shape[0] > 9) & (shape[1] > 9), f'image size {shape} <10 pixels'
1059
  assert im.format.lower() in img_formats, f'invalid image format {im.format}'
1060
 
1061
  # verify labels
1062
+ segments = [] # instance segments
1063
  if os.path.isfile(lb_file):
1064
  nf = 1 # label found
1065
  with open(lb_file, 'r') as f:
 
1084
  except Exception as e:
1085
  nc = 1
1086
  logging.info(f'{prefix}WARNING: Ignoring corrupted image and/or label {im_file}: {e}')
1087
+ return [None, None, None, None, nm, nf, ne, nc]
1088
 
1089
 
1090
  def dataset_stats(path='coco128.yaml', autodownload=False, verbose=False):