def __init__(self,data_file):
        print('Reading data...')
        self.fnames = []
        f = open(data_file)
        self.data = []
        cnt = 0
        for i in f:
            i = i.strip().split('\t')
            jpgfile = i[0]

            # get jpg, seg, mask
            jpg = img_reader.read_img(jpgfile,500,padding=True)
            seg = data_provider.get_seg(jpgfile)
            seg = img_reader.pad(seg,np.uint8,False)
            mask = seg.copy()
            seg[seg==255] = 0
            mask[mask!=0] = 1
            coords = data_provider.get_coord_map(jpgfile)
            coords = img_reader.pad(coords,np.float32,6)
            inst_num = data_provider.get_inst_num(jpgfile)

            if seg.shape[0]!=500:
                print(jpgfile)
                continue

            # if size is ok, add to data list
            self.data.append([jpg,seg,mask,coords,inst_num])
            self.fnames.append(jpgfile)
            cnt += 1
            if cnt%100==0:
                print(cnt)
Beispiel #2
0
 def __init__(self, data_file):
     print('Reading data...')
     self.fnames = []
     f = open(data_file)
     self.data = []
     cnt = 0
     for i in f:
         i = i.strip()
         jpgfile = './data/reform_img/' + i
         segfile = './data/reform_annot/' + i.replace('.jpg', '.png')
         jpg = img_reader.read_img(jpgfile, 500, padding=True)
         seg = self.read_label(segfile)
         seg = img_reader.pad(seg, np.uint8, False)
         mask = seg.copy()
         seg[seg == 255] = 0
         mask[mask != 0] = 1
         if seg.shape[0] != 500:
             print(segfile)
             continue
         self.data.append([jpg, seg, mask])
         self.fnames.append(jpgfile)
         cnt += 1
         if cnt % 100 == 0:
             print(cnt)
     print('Data length:', len(self.data))
Beispiel #3
0
 def __init__(self, data_file):
     print('Reading data...')
     self.fnames = []
     f = open(data_file)
     self.data = []
     cnt = 0
     for i in f:
         i = i.strip()
         segfile = i
         jpgfile = i.replace('SegmentationClass',
                             'JPEGImages').replace('.png', '.jpg')
         jpg = img_reader.read_img(jpgfile, 500, padding=True)
         seg = self.read_label(segfile)
         seg = img_reader.pad(seg, np.uint8, False)
         seg[seg != 15] = 0
         seg[seg == 15] = 1
         if seg.shape[0] != 500:
             print(segfile)
             continue
         self.data.append([jpg, seg])
         self.fnames.append(jpgfile)
         cnt += 1
         if cnt % 100 == 0:
             print(cnt)
     print('Data length:', len(self.data))
Beispiel #4
0
 def __init__(self,data_file):
     print('Reading data...')
     self.fnames = []
     f = open(data_file)
     self.data = []
     cnt = 0
     for i in f:
         try:
             i = i.strip()
             segfile = i.split('\t')[1]
             jpgfile = i.split('\t')[0]
             jpg = img_reader.read_img(jpgfile,500,padding=True)
             seg = self.read_label(segfile)
             seg = img_reader.pad(seg,np.uint8,False)
             seg[seg!=15] = 0
             seg[seg==15] = 1
             if seg.shape[0]!=500:
                 print(segfile)
                 continue
             self.data.append([jpg,seg])
             self.fnames.append(jpgfile)
             cnt += 1
             if cnt%100==0:
                 print(cnt)
         except:
             pass
     print('Data length:',len(self.data))
Beispiel #5
0
 def eval(self, img_path):
     img = img_reader.read_img(img_path, None, scale=False)
     msk, seg, inst_num, coord = self.sess.run(
         [self.mask_out, self.seg_out, self.inst_num_out, self.coord_out],
         feed_dict={self.img_holder: [img]})
     msk, seg, inst = util.get_output_img(msk[0], seg[0], inst_num[0],
                                          coord[0])
     return msk, seg, inst
Beispiel #6
0
with tf.variable_scope('seg_part'):
    net = network(21)

MAX_ITER = 100000
BSIZE = 1
for i in range(MAX_ITER):
    img_batch, lab_batch, mask_batch = reader.next_batch(BSIZE)
    loss = net.train(img_batch, lab_batch, mask_batch)
    print('Iter:%d\tLoss:%.4f' % (i, loss))

    # monitor the training process
    if i % 10 == 0:
        fname = random.sample(reader.fnames, 1)
        img = cv2.imread(fname[0])
        img = img_reader.pad(img, np.uint8)
        img_inp = img_reader.read_img(fname[0], 500, True)

        mask = read_label(fname[0].replace('reform_img',
                                           'reform_annot').replace(
                                               'jpg', 'png'))
        mask = img_reader.pad(mask, np.uint8, False)
        mask[mask != 0] = 1

        img = img[20:480, 20:480]
        img_inp = img_inp[20:480, 20:480]
        mask = mask[20:480, 20:480]

        res = net.eval([img_inp], [mask])
        res = np.uint8(res)
        res = cv2.resize(res, (img.shape[1], img.shape[0]),
                         interpolation=cv2.INTER_NEAREST)