Single class train update (#1719)
Browse files
train.py
CHANGED
@@ -71,7 +71,8 @@ def train(hyp, opt, device, tb_writer=None, wandb=None):
|
|
71 |
check_dataset(data_dict) # check
|
72 |
train_path = data_dict['train']
|
73 |
test_path = data_dict['val']
|
74 |
-
nc
|
|
|
75 |
assert len(names) == nc, '%g names found for nc=%g dataset in %s' % (len(names), nc, opt.data) # check
|
76 |
|
77 |
# Model
|
@@ -447,7 +448,7 @@ if __name__ == '__main__':
|
|
447 |
parser.add_argument('--image-weights', action='store_true', help='use weighted image selection for training')
|
448 |
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
|
449 |
parser.add_argument('--multi-scale', action='store_true', help='vary img-size +/- 50%%')
|
450 |
-
parser.add_argument('--single-cls', action='store_true', help='train as single-class
|
451 |
parser.add_argument('--adam', action='store_true', help='use torch.optim.Adam() optimizer')
|
452 |
parser.add_argument('--sync-bn', action='store_true', help='use SyncBatchNorm, only available in DDP mode')
|
453 |
parser.add_argument('--local_rank', type=int, default=-1, help='DDP parameter, do not modify')
|
|
|
71 |
check_dataset(data_dict) # check
|
72 |
train_path = data_dict['train']
|
73 |
test_path = data_dict['val']
|
74 |
+
nc = 1 if opt.single_cls else int(data_dict['nc']) # number of classes
|
75 |
+
names = ['item'] if opt.single_cls and len(data_dict['names']) != 1 else data_dict['names'] # class names
|
76 |
assert len(names) == nc, '%g names found for nc=%g dataset in %s' % (len(names), nc, opt.data) # check
|
77 |
|
78 |
# Model
|
|
|
448 |
parser.add_argument('--image-weights', action='store_true', help='use weighted image selection for training')
|
449 |
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
|
450 |
parser.add_argument('--multi-scale', action='store_true', help='vary img-size +/- 50%%')
|
451 |
+
parser.add_argument('--single-cls', action='store_true', help='train multi-class data as single-class')
|
452 |
parser.add_argument('--adam', action='store_true', help='use torch.optim.Adam() optimizer')
|
453 |
parser.add_argument('--sync-bn', action='store_true', help='use SyncBatchNorm, only available in DDP mode')
|
454 |
parser.add_argument('--local_rank', type=int, default=-1, help='DDP parameter, do not modify')
|