Example #1
0
    def get_big_data(self):
        big_root = './data/shtu_dataset/original/'
        part_A_train = os.path.join(big_root, 'part_A_final/train_data', 'images')
        part_A_test = os.path.join(big_root, 'part_A_final/test_data', 'images')
        path_sets = [part_A_train, part_A_test]
        big_list = []

        for path in path_sets:
            for img_path in glob.glob(os.path.join(path, '*.jpg')):
                mat = io.loadmat(
                    img_path.replace('.jpg', '.mat').replace('images', 'ground_truth').replace('IMG_', 'GT_IMG_'))
                number = mat["image_info"][0, 0][0, 0][1]
                if number[0, 0] >= 400:
                    big_list.append(img_path)

        return big_list
Example #2
0
    def flows_mat_to_np(self):

        self.logger.info('Converting MATLAB flows to Numpy')
        flows_mat_path = sorted(glob.glob(os.path.join(self.conf.root_path, self.conf.ds_dir,self.conf.frameDir,'TSP_flows','*flow.mat')))

        flows_mat = [io.loadmat(flows_mat_path[i]) for i in range(len(flows_mat_path))]
        flows_bvx = [flows_mat[i]['flow'][0][0][0] for i in range(len(flows_mat))]
        flows_bvy = [flows_mat[i]['flow'][0][0][1] for i in range(len(flows_mat))]
        flows_fvx = [flows_mat[i]['flow'][0][0][2] for i in range(len(flows_mat))]
        flows_fvy = [flows_mat[i]['flow'][0][0][3] for i in range(len(flows_mat))]

        flows_np = dict()
        flows_np['bvx'] = np.asarray(flows_bvx).transpose(1,2,0)
        flows_np['bvy'] = np.asarray(flows_bvy).transpose(1,2,0)
        flows_np['fvx'] = np.asarray(flows_fvx).transpose(1,2,0)
        flows_np['fvy'] = np.asarray(flows_fvy).transpose(1,2,0)

        file_out = os.path.join(self.conf.precomp_desc_path,'flows.npz')
        self.logger.info('Saving optical flows to: ' + file_out)
        np.savez(file_out, **flows_np)

        return flows_np
Example #3
0
 def __init__(self, **kwargs):
     """Load the dataset.
     kwargs:
         root: the root folder of the CUB_200_2011 dataset.
         is_training: if true, load the training data. Otherwise, load the
             testing data.
         crop: if None, does not crop the bounding box. If a real value,
             crop is the ratio of the bounding box that gets cropped.
             e.g., if crop = 1.5, the resulting image will be 1.5 * the
             bounding box area.
         target_size: all images are resized to the size specified. Should
             be a tuple of two integers, like [256, 256].
         version: either '2011' or '2010'.
     Note that we will use the python indexing (labels start from 0).
     """
     root = kwargs['root']
     is_training = kwargs.get('is_training', True)
     crop = kwargs.get('crop', None)
     target_size = kwargs['target_size']
     version = kwargs.get('version', '2011')
     if version == '2011':
         images = [
             line.split()[1]
             for line in open(os.path.join(root, 'images.txt'), 'r')
         ]
         boxes = [
             line.split()[1:]
             for line in open(os.path.join(root, 'bounding_boxes.txt'), 'r')
         ]
         labels = [
             int(line.split()[1]) - 1 for line in open(
                 os.path.join(root, 'image_class_labels.txt'), 'r')
         ]
         birdnames = [
             line.split()[1]
             for line in open(os.path.join(root, 'classes.txt'), 'r')
         ]
         name_to_id = dict(zip(birdnames, range(len(birdnames))))
         split = [
             int(line.split()[1]) for line in open(
                 os.path.join(root, 'train_test_split.txt'), 'r')
         ]
     elif version == '2010':
         # we are using version 2010. We load the data to mimic the 2011
         # version data format
         images = [
             line.strip()
             for line in open(os.path.join(root, 'lists', 'files.txt'), 'r')
         ]
         boxes = []
         # unfortunately, we need to load the boxes from matlab annotations
         for filename in images:
             matfile = io.loadmat(
                 os.path.join(root, 'annotations-mat',
                              filename[:-3] + 'mat'))
             left, top, right, bottom = \
                     [matfile['bbox'][0][0][i][0][0] for i in range(4)]
             boxes.append([left, top, right - left, bottom - top])
         # get the training and testing split.
         train_images = [
             line.strip()
             for line in open(os.path.join(root, 'lists', 'train.txt'), 'r')
         ]
         labels = [int(line[:line.find('.')]) - 1 for line in images]
         birdnames = [
             line.strip() for line in open(
                 os.path.join(root, 'lists', 'classes.txt'), 'r')
         ]
         name_to_id = dict(zip(birdnames, range(len(birdnames))))
         split = [int(line in train_images) for line in images]
     else:
         raise ValueError, "Unrecognized version: %s" % version
     # now, do training testing split
     if is_training:
         target = 1
     else:
         target = 0
     images = [image for image, val in zip(images, split) if val == target]
     boxes = [box for box, val in zip(boxes, split) if val == target]
     label = [label for label, val in zip(labels, split) if val == target]
     # for the boxes, we store them as a numpy array
     boxes = np.array(boxes, dtype=np.float32)
     boxes -= 1
     # load the data
     self._data = None
     self._load_data(root, images, boxes, crop, target_size)
     self._label = np.asarray(label, dtype=np.int)
     ndarraydata.NdarrayDataLayer.__init__(
         self, sources=[self._data, self._label], **kwargs)
src_folder = '/tmp/jhmdb/'

f = open(filelist, 'r')
gts = []
heights = []
widths = []
preds = []
jnt_visible_set = []
human_boxes = []

feat_res = 40

for cnt, line in enumerate(f):
    rows = line.strip().split()
    lblpath = rows[1]  #+ '/joint_positions.mat'
    lbls_mat = sio.loadmat(lblpath)
    lbls_coord = lbls_mat['pos_img']
    lbls_coord = lbls_coord - 1

    gts.append(lbls_coord)

    imgpath = rows[0] + '/00001.png'
    img = cv2.imread(imgpath)
    heights.append(img.shape[0])
    widths.append(img.shape[1])

f.close()

# gts = gts[0: 200]
print('read gt')
Example #5
0
    return labels


#datasets = ['Dataset1','Dataset2','Dataset3','Dataset4','Dataset9','Dataset11','Dataset12','Dataset13','Dataset14','Dataset15','Dataset16','Dataset17','Dataset18','Dataset20']
#datasets = ['Dataset1','Dataset2','Dataset3','Dataset4','Dataset9','Dataset11','Dataset12','Dataset13','Dataset14','Dataset15','Dataset16','Dataset17','Dataset18']
#datasets = ['Dataset15']
datasets = ['Dataset13']

dir_root = '/home/laurent.lejeune/medical-labeling'
dir_frames = 'input-frames'

for i in range(len(datasets)):

    old_labels = io.loadmat(
        os.path.join(dir_root, datasets[i], dir_frames,
                     'sp_labels.mat'))['sp_labels']

    new_labels = relabel(old_labels)

    data = dict()
    data['sp_labels'] = new_labels
    mat_file_out = os.path.join(dir_root, datasets[i], dir_frames,
                                'sp_labels.npz')
    np.savez(mat_file_out, **data)

    sp_desc_df = pd.read_pickle(
        os.path.join(dir_root, datasets[i], 'precomp_descriptors',
                     'sp_desc_df.p'))

    ##Move old
Example #6
0
 def __init__(self, **kwargs):
     """Load the dataset.
     kwargs:
         root: the root folder of the CUB_200_2011 dataset.
         is_training: if true, load the training data. Otherwise, load the
             testing data.
         crop: if None, does not crop the bounding box. If a real value,
             crop is the ratio of the bounding box that gets cropped.
             e.g., if crop = 1.5, the resulting image will be 1.5 * the
             bounding box area.
         target_size: all images are resized to the size specified. Should
             be a tuple of two integers, like [256, 256].
         version: either '2011' or '2010'.
     Note that we will use the python indexing (labels start from 0).
     """
     root = kwargs['root']
     is_training = kwargs.get('is_training', True)
     crop = kwargs.get('crop', None)
     target_size = kwargs['target_size']
     version = kwargs.get('version', '2011')
     if version == '2011':
         images = [line.split()[1] for line in
                     open(os.path.join(root, 'images.txt'), 'r')]
         boxes = [line.split()[1:] for line in
                     open(os.path.join(root, 'bounding_boxes.txt'),'r')]
         labels = [int(line.split()[1]) - 1 for line in 
                     open(os.path.join(root, 'image_class_labels.txt'), 'r')]
         birdnames = [line.split()[1] for line in
                       open(os.path.join(root, 'classes.txt'), 'r')]
         name_to_id = dict(zip(birdnames, range(len(birdnames))))
         split = [int(line.split()[1]) for line in
                     open(os.path.join(root, 'train_test_split.txt'),'r')]
     elif version == '2010':
         # we are using version 2010. We load the data to mimic the 2011
         # version data format
         images = [line.strip() for line in
                     open(os.path.join(root, 'lists', 'files.txt'), 'r')]
         boxes = []
         # unfortunately, we need to load the boxes from matlab annotations
         for filename in images:
             matfile = io.loadmat(os.path.join(root, 'annotations-mat',
                                               filename[:-3]+'mat'))
             left, top, right, bottom = \
                     [matfile['bbox'][0][0][i][0][0] for i in range(4)]
             boxes.append([left, top, right-left, bottom-top])
         # get the training and testing split.
         train_images = [line.strip() for line in
                     open(os.path.join(root, 'lists', 'train.txt'), 'r')]
         labels = [int(line[:line.find('.')]) - 1 for line in images]
         birdnames = [line.strip() for line in
                     open(os.path.join(root, 'lists', 'classes.txt'),'r')]
         name_to_id = dict(zip(birdnames, range(len(birdnames))))
         split = [int(line in train_images) for line in images]
     else:
         raise ValueError, "Unrecognized version: %s" % version
     # now, do training testing split
     if is_training:
         target = 1
     else:
         target = 0
     images = [image for image, val in zip(images, split) if val == target]
     boxes = [box for box, val in zip(boxes, split) if val == target]
     label = [label for label, val in zip(labels, split) if val == target]
     # for the boxes, we store them as a numpy array
     boxes = np.array(boxes, dtype=np.float32)
     boxes -= 1
     # load the data
     self._data = None
     self._load_data(root, images, boxes, crop, target_size)
     self._label = np.asarray(label, dtype=np.int)
     ndarraydata.NdarrayDataLayer.__init__(
         self, sources=[self._data, self._label], **kwargs)
currentIndex = 1
#GENERATE STRINGS
for i in range(1,maxIndex+1):
	currentSNR = SNRs[SNRIndex]
	currentString = 'SEN'+str(i)+'_'+str(currentSNR)+'_'+noiseType+'.mat'
	allStrings.append(currentString)
	SNRIndex += 1
	if (SNRIndex == 9):
		SNRIndex = 0
print("LOADING DATA")

AIMImages = list()
for i in range(0,maxIndex):
	currentFileLocation = AIMImagesFolder + allStrings[i]
	currentTargetLocation = targetsFolder + allStrings[i]
	currentFile = io.loadmat(currentFileLocation)
	currentFile = np.array(currentFile['AIMImages'])
	currentTarget = io.loadmat(currentTargetLocation)
	currentTarget = np.transpose(currentTarget['target'])
	if(i == 0):
	 	targets = currentTarget 
	else:
	 	targets = np.concatenate((targets,currentTarget),0)
	AIMImages.append(currentFile)

	print("FILE IN : " + currentFileLocation + " LOADED")
AIMImages = np.dstack(AIMImages)
print("DATA LOADED")
Xtraining = AIMImages
Xtraining = np.swapaxes(Xtraining,2,1)
Xtraining = np.swapaxes(Xtraining,0,1)