Esempio n. 1
0
 def get_img(self, img_path):
     img = cv2.imread(img_path)
     crop = img_ops.center_crop(
         img, self.crop_size,
         self.crop_size) if self.crop_size is not None else img
     resized_img = cv2.resize(
         crop, (self.out_size,
                self.out_size)) if self.out_size is not None else crop
     return img_ops.bound_image_values(resized_img)
Esempio n. 2
0
 def generate_train_mb(self):
     train_size = self.lab_data.shape[0]
     for i in xrange(0, train_size, self.batch_size):
         lab_data_batch = self.lab_data[i:i + self.batch_size, :, :, :]
         labels_batch = self.labels[i:i + self.batch_size]
         lab_data_batch, labels_batch = self.fill_batch(
             lab_data_batch, labels_batch, self.lab_data, self.labels)
         yield bound_image_values(lab_data_batch).astype(
             np.float32), self.one_hot_labels(labels_batch)
Esempio n. 3
0
 def generate_train_mb(self):
     train_size = self.unlab_data.shape[0]
     for i in xrange(0, train_size, self.batch_size):
         data_batch = self.unlab_data[i:i + self.batch_size, :, :, :]
         if data_batch.shape[0] < self.batch_size:
             data_batch = np.concatenate(
                 (data_batch,
                  self.unlab_data[0:self.batch_size -
                                  data_batch.shape[0], :, :, :]))
         yield bound_image_values(data_batch).astype(np.float32)
Esempio n. 4
0
    def generate_test_mb(self):
        for i in xrange(0, self.test_data.shape[0], self.batch_size):
            data_batch = self.test_data[i:i + self.batch_size, :, :, :]
            labels_batch = self.test_labels[i:i + self.batch_size]

            data_batch, labels_batch = self.fill_batch(data_batch,
                                                       labels_batch,
                                                       self.test_data,
                                                       self.test_labels)
            data_batch = bound_image_values(data_batch).astype(np.float32)
            yield data_batch, self.one_hot_labels(labels_batch)
Esempio n. 5
0
    def generate_train_mb(self):
        train_size = self.unlab_data.shape[0]
        inds = self.rng.permutation(train_size)
        unlab_data = self.unlab_data[inds, :, :, :]
        lab_data, labels = self.extend_labeled_data(self.lab_data, self.labels,
                                                    unlab_data)

        for i in xrange(0, train_size, self.batch_size):
            lab_data_batch = lab_data[i:i + self.batch_size, :, :, :]
            unlab_data_batch = unlab_data[i:i + self.batch_size, :, :, :]
            labels_batch = labels[i:i + self.batch_size]
            lab_data_batch, labels_batch = self.fill_batch(
                lab_data_batch, labels_batch, lab_data, labels)

            if unlab_data_batch.shape[0] < self.batch_size:
                unlab_data_batch = np.concatenate(
                    (unlab_data_batch, unlab_data[0:self.batch_size -
                                                  unlab_data_batch.shape[0]]),
                    axis=0)

            yield bound_image_values(lab_data_batch).astype(np.float32), \
                  bound_image_values(unlab_data_batch).astype(np.float32), self.one_hot_labels(labels_batch)
def transform(img_arr, scale_img_opt):
    if scale_img_opt == '0_to_1':
        return img_ops.bound_image_values_01(img_arr).astype(np.float32)
    else:
        return img_ops.bound_image_values(img_arr).astype(np.float32)