Esempio n. 1
0
def predictGenerator(test_path,
                     batch_size=2,
                     percent=1,
                     dim=(256, 256),
                     n_channels=1,
                     save_path='test_result/'):
    if not os.path.exists(save_path):
        os.makedirs(save_path)
    files = random.sample(test_path, int(np.ceil(len(test_path) * percent)))
    for i, item in enumerate(files):
        img_array = img_load(os.path.join(item[0]), shape=dim, norm=True)
        lab_array = lab_load(os.path.join(item[1]),
                             shape=dim,
                             norm=False,
                             binary=True)
        img_save_name = str(i) + "_source_img_" + os.path.splitext(
            os.path.split(item[0])[1])[0] + '.png'
        lab_save_name = str(i) + "_source_label_" + os.path.split(item[1])[1]
        imgdata = img_array * 255
        labdata = lab_array * 255
        io.imsave(os.path.join(save_path, img_save_name),
                  imgdata.clip(0, 255, imgdata).astype(np.uint8))
        io.imsave(os.path.join(save_path, lab_save_name),
                  labdata.clip(0, 255, labdata).astype(np.uint8))
        img_array = np.reshape(img_array, img_array.shape + (1, ))
        img_array = np.reshape(img_array, (1, ) + img_array.shape)
        yield img_array
Esempio n. 2
0
def testGenerator(test_path, num_image=50, target_size=(256, 256), result_path='test_result/'):
    filelist = travel_testfiles(test_path)
    files = random.sample(filelist, num_image)
    for i, item in enumerate(files):
        img_array = img_load(os.path.join(test_path, item), shape=target_size, norm=True)
        io.imsave(os.path.join(result_path, "%d_source.png" % i), img_array)
        img_array = np.reshape(img_array, img_array.shape + (1,))
        img_array = np.reshape(img_array, (1,) + img_array.shape)
        yield img_array
Esempio n. 3
0
 def __data_generation(self, list_IDs_temp):
     X = np.empty((self.batch_size, *self.dim, self.n_channels))
     # print('X.shape', X.shape)
     y1 = np.empty((self.batch_size, *self.dim, 1))
     # print('y1.shape', y1.shape)
     for i, item in enumerate(list_IDs_temp):
         img_array = img_load(item[0], shape=(256, 256), norm=True)
         lab_array = lab_load(item[1],
                              shape=(256, 256),
                              norm=False,
                              binary=True)
         img_array = img_array.reshape(*img_array.shape, self.n_channels)
         lab_array = lab_array.reshape(*lab_array.shape, self.n_channels)
         if self.datagen:
             seed = random.randint(1, 10000)
             img_array = self.datagen.random_transform(img_array, seed)
             lab_array = self.datagen.random_transform(lab_array, seed)
         # print('each_img_shape', img_array.shape)
         # print('each_lab_shape', lab_array.shape)
         X[i, ] = img_array
         y1[i, ] = lab_array
     return X, y1