tanluren / yolov3-channel-and-layer-pruning

yolov3 yolov4 channel and layer pruning, Knowledge Distillation 层剪枝,通道剪枝,知识蒸馏
Apache License 2.0
1.5k stars 446 forks source link

About UnboundLocalError: local variable 'labels' referenced before assignment #86

Open ClayZhang0403 opened 4 years ago

ClayZhang0403 commented 4 years ago

当训练的时候就出现了这个问题UnboundLocalError: local variable 'labels' referenced before assignment,我的数据集中有一部分负样本,但是不知道这个问题该怎么解决,求楼主或者其他大佬赐教

zbyuan commented 4 years ago

13.2020/4/30在datasets.py 592行添加了支持负样本训练,默认注释掉.

kimkimyoung commented 4 years ago

把append缩进 ` # Load labels label_path = self.label_files[index] if os.path.isfile(label_path): x = self.labels[index] if x is None: # labels not preloaded with open(label_path, 'r') as f: x = np.array([x.split() for x in f.read().splitlines()], dtype=np.float32)

        if x.size > 0:
            # Normalized xywh to pixel xyxy format
            labels = x.copy()
            labels[:, 1] = w * (x[:, 1] - x[:, 3] / 2) + padw
            labels[:, 2] = h * (x[:, 2] - x[:, 4] / 2) + padh
            labels[:, 3] = w * (x[:, 1] + x[:, 3] / 2) + padw
            labels[:, 4] = h * (x[:, 2] + x[:, 4] / 2) + padh

            labels4.append(labels)
if len(labels4):
    labels4 = np.concatenate(labels4, 0)`
wsypy commented 3 years ago

把append缩进 ` # Load labels label_path = self.label_files[index] if os.path.isfile(label_path): x = self.labels[index] if x is None: # labels not preloaded with open(label_path, 'r') as f: x = np.array([x.split() for x in f.read().splitlines()], dtype=np.float32)

        if x.size > 0:
            # Normalized xywh to pixel xyxy format
            labels = x.copy()
            labels[:, 1] = w * (x[:, 1] - x[:, 3] / 2) + padw
            labels[:, 2] = h * (x[:, 2] - x[:, 4] / 2) + padh
            labels[:, 3] = w * (x[:, 1] + x[:, 3] / 2) + padw
            labels[:, 4] = h * (x[:, 2] + x[:, 4] / 2) + padh

            labels4.append(labels)
if len(labels4):
    labels4 = np.concatenate(labels4, 0)`

没看明白啥意思。能再明确些吗,我也有负样本,这里出错了,谢谢