Exemple #1
0
    def __init__(self, split, config, phase='train'):
        assert (phase == 'train' or phase == 'val' or phase == 'test')

        self.random_sample = config['random_sample']  #True
        self.T = config['T']  #1
        self.topk = config['topk']  #5
        self.crop_size = config['crop_size']  #[96,96,96]
        self.stride = config['stride']  #4
        self.augtype = config[
            'augtype']  #{'flip':True,'swap':False,'rotate':False,'scale':False}
        #self.labels = np.array(pandas.read_csv(config['labelfile']))

        datadir = config['datadir']  #preprocess_result_path
        bboxpath = config['bboxpath']  #'../detector/results/res18/bbox/',
        self.phase = phase
        self.candidate_box = []
        self.pbb_label = []

        split = [str(f, 'utf-8') for f in split]
        idcs = split
        self.filenames = [
            os.path.join(datadir, '%s_clean.npy' % idx) for idx in idcs
        ]
        labels = np.array(pandas.read_csv(
            config['labelfile']))  #'./full_label.csv'
        if phase != 'test':
            # print('0',labels[:,0])
            # print('0=', [str(f,'utf-8') for f in split])
            # self.yset = np.array([labels[labels[:,0]==str(f,'utf-8'),1] for f in split]).astype('int')
            self.yset = np.array([
                labels[labels[:, 0] == f.split('-')[0].split('_')[0], 1]
                for f in split
            ]).astype('int')
        # print([str(f,'utf-8') for f in idcs])
        # idcs = [str(f,'utf-8') for f in idcs]

        for idx in idcs:
            pbb = np.load(os.path.join(bboxpath, idx + '_pbb.npy'))
            # print('pbb.shape',pbb.shape)#(~,5)
            pbb = pbb[pbb[:, 0] > config['conf_th']]  #-1
            pbb = nms(pbb, config['nms_th'])  #0.05

            lbb = np.load(os.path.join(bboxpath, idx + '_lbb.npy'))
            pbb_label = []

            for p in pbb:
                isnod = False
                for l in lbb:
                    score = iou(p[1:5], l)
                    if score > config['detect_th']:  #0.05
                        isnod = True
                        break
                pbb_label.append(isnod)


#             if idx.startswith()
            self.candidate_box.append(pbb)
            self.pbb_label.append(np.array(pbb_label))
        self.crop = simpleCrop(config, phase)
    def __init__(self, split, config, phase='train'):
        assert (phase == 'train' or phase == 'val' or phase == 'test')

        self.random_sample = config['random_sample']
        self.T = config['T']
        self.topk = config['topk']
        self.crop_size = config['crop_size']
        self.stride = config['stride']
        self.augtype = config['augtype']
        # self.labels = np.array(pandas.read_csv(config['labelfile']))

        datadir = config['datadir']
        bboxpath = config['bboxpath']
        self.phase = phase
        self.candidate_box = []
        self.pbb_label = []

        idcs = split
        self.filenames = [
            os.path.join(datadir, '%s_clean.npy' % idx) for idx in idcs
        ]
        labels = np.array(pandas.read_csv(config['labelfile']))
        if phase != 'test':
            self.yset = np.array([
                labels[labels[:, 0] == f.split('-')[0].split('_')[0], 1]
                for f in split
            ]).astype('int')
        idcs = [f.split('-')[0] for f in idcs]
        '''
        1. 对目标检测过的预测结果做nms
        2. 提取使用到的label    
        3. self.pbb_label 预测结果中是否含有目标的label
        4. self.candidate_box 候选框pbb 为预测结果的加载,疑似存在目标
        5. yset 为分类的annotations
        '''

        for idx in idcs:
            # output shape = n*[conf,z,h,w,d]
            pbb = np.load(os.path.join(bboxpath, idx + '_pbb.npy'))
            pbb = pbb[pbb[:, 0] > config['conf_th']]
            pbb = nms(pbb, config['nms_th'])

            lbb = np.load(os.path.join(bboxpath, idx + '_lbb.npy'))
            pbb_label = []

            for p in pbb:
                isnod = False
                for l in lbb:
                    score = iou(p[1:5], l)
                    if score > config['detect_th']:
                        isnod = True
                        break
                pbb_label.append(isnod)
            #             if idx.startswith()
            self.candidate_box.append(pbb)
            self.pbb_label.append(np.array(pbb_label))
        self.crop = simpleCrop(config, phase)
Exemple #3
0
    def __init__(self, dirlist, config, phase='train'):
        assert (phase in {'train', 'val', 'test'})

        self.random_sample = config['random_sample']
        self.T = config['T']
        self.topk = config['topk']
        self.crop_size = config['crop_size']
        self.stride = config['stride']
        self.augtype = config['augtype']
        self.filling_value = config['filling_value']

        # self.labels = np.array(pandas.read_csv(config['labelfile']))

        datadir = config['datadir']
        bboxpath = config['bboxpath']
        self.phase = phase
        self.candidate_box = []
        self.pbb_label = []

        idcs = dirlist

        self.filenames = [
            p.join(datadir, '%s_clean.npy' % idx.split('-')[0]) for idx in idcs
        ]

        if self.phase != 'test':
            self.yset = 1 - np.array([f.split('-')[1][2]
                                      for f in idcs]).astype('int')

        for idx in idcs:
            pbb = np.load(p.join(bboxpath, idx + '_pbb.npy'))
            pbb = pbb[pbb[:, 0] > config['conf_th']]
            pbb = nms(pbb, config['nms_th'])

            lbb = np.load(p.join(bboxpath, idx + '_lbb.npy'))
            pbb_label = []

            for pb in pbb:
                isnod = False

                for lb in lbb:
                    score = iou(pb[1:5], lb)

                    if score > config['detect_th']:
                        isnod = True
                        break

                pbb_label.append(isnod)

            # if idx.startswith()
            self.candidate_box.append(pbb)
            self.pbb_label.append(np.array(pbb_label))

        self.crop = simpleCrop(config, phase)
Exemple #4
0
    def __init__(self, split, config, phase = 'train'):
        assert(phase == 'train' or phase == 'val' or phase == 'test')
        
        self.random_sample = config['random_sample']
        self.T = config['T']
        self.topk = config['topk']
        self.crop_size = config['crop_size']
        self.stride = config['stride']
        #print ('------------stride: ', self.stride)
        self.augtype  = config['augtype']
        self.filling_value = config['filling_value']
        
        #self.labels = np.array(pandas.read_csv(config['labelfile']))
        
        datadir = config['datadir']
        bboxpath  = config['bboxpath']
        self.phase = phase
        self.candidate_box = []
        self.pbb_label = []
        self.subj_name = []
        idcs = split
        self.filenames = [os.path.join(datadir, '%s_clean.npy' % idx.split('-')[0]) for idx in idcs]
        if self.phase!='test':
            self.yset = 1-np.array([f.split('-')[1][2] for f in idcs]).astype('int')
 
        
        for idx in idcs:
            #print ('This is ', idx)
            try:
                pbb = np.load(os.path.join(bboxpath,idx+'_pbb.npy'))
            except:
                print (idx+'_pbb.npy not existed' )
                continue
            pbb = pbb[pbb[:,0]>config['conf_th']]
            pbb = nms(pbb, config['nms_th'])
            
            lbb = np.load(os.path.join(bboxpath,idx+'_lbb.npy'))
            pbb_label = []
            
            for p in pbb:
                isnod = False
                for l in lbb:
                    score = iou(p[1:5], l)
                    if score > config['detect_th']:
                        isnod = True
                        break
                pbb_label.append(isnod)
#             if idx.startswith()
            self.subj_name.append(idx)
            self.candidate_box.append(pbb)
            self.pbb_label.append(np.array(pbb_label))
        self.crop = simpleCrop(config,phase)
Exemple #5
0
    def __init__(self, split, config, phase = 'train'):
        assert(phase == 'train' or phase == 'val' or phase == 'test')
        
        self.random_sample = config['random_sample']
        self.T = config['T']
        self.topk = config['topk']
        self.crop_size = config['crop_size']
        self.stride = config['stride']
        self.augtype  = config['augtype']
        #self.labels = np.array(pandas.read_csv(config['labelfile']))
        
        datadir = config['datadir']
        bboxpath  = config['bboxpath']
        self.phase = phase
        self.candidate_box = []
        self.pbb_label = []
        
        idcs = split
        self.filenames = [os.path.join(datadir, '%s_clean.npy' % idx) for idx in idcs]
        labels = np.array(pandas.read_csv(config['labelfile']))
        if phase !='test':
            for tmp in [labels[labels[:, 0] == f.split('-')[0].split('_')[0], 1] for f in split]:
                print(tmp.shape)
	    print([labels[labels[:,0]==f.split('-')[0].split('_')[0],1] for f in split])
            self.yset = np.array([labels[labels[:,0]==f.split('-')[0].split('_')[0],1] for f in split]).astype('int')
        idcs = [f.split('-')[0] for f in idcs]
        
        
        for idx in idcs:
            pbb = np.load(os.path.join(bboxpath,idx+'_pbb.npy'))
            pbb = pbb[pbb[:,0]>config['conf_th']]
            pbb = nms(pbb, config['nms_th'])
            
            lbb = np.load(os.path.join(bboxpath,idx+'_lbb.npy'))
            pbb_label = []
            
            for p in pbb:
                isnod = False
                for l in lbb:
                    score = iou(p[1:5], l)
                    if score > config['detect_th']:
                        isnod = True
                        break
                pbb_label.append(isnod)
#             if idx.startswith()
            self.candidate_box.append(pbb)
            self.pbb_label.append(np.array(pbb_label))
        self.crop = simpleCrop(config,phase)
Exemple #6
0
    def __init__(self, split, config, phase = 'train'):
        assert(phase == 'train' or phase == 'val' or phase == 'test')
        
        self.random_sample = config['random_sample']
        self.T = config['T']
        self.topk = config['topk']
        self.crop_size = config['crop_size']
        self.stride = config['stride']
        self.augtype  = config['augtype']
        self.filling_value = config['filling_value']
        
        #self.labels = np.array(pandas.read_csv(config['labelfile']))
        
        datadir = config['datadir']
        bboxpath  = config['bboxpath']
        self.phase = phase
        self.candidate_box = []
        self.pbb_label = []
        
        idcs = split
        self.filenames = [os.path.join(datadir, '%s_clean.npy' % idx.split('-')[0]) for idx in idcs]
        if self.phase!='test':
            self.yset = 1-np.array([f.split('-')[1][2] for f in idcs]).astype('int')
 
        
        for idx in idcs:
            pbb = np.load(os.path.join(bboxpath,idx+'_pbb.npy'))
            pbb = pbb[pbb[:,0]>config['conf_th']]
            pbb = nms(pbb, config['nms_th'])
            
            lbb = np.load(os.path.join(bboxpath,idx+'_lbb.npy'))
            pbb_label = []
            
            for p in pbb:
                isnod = False
                for l in lbb:
                    score = iou(p[1:5], l)
                    if score > config['detect_th']:
                        isnod = True
                        break
                pbb_label.append(isnod)
#             if idx.startswith()
            self.candidate_box.append(pbb)
            self.pbb_label.append(np.array(pbb_label))
        self.crop = simpleCrop(config,phase)