Esempio n. 1
0
 def test_merge(self):
     pipe_const0 = utp.Inputer(item='test')
     pipe_const1 = utp.Inputer(item='test')
     pipe_const2 = utp.Inputer(item='test')
     pipe_merge = utp.Pipe([pipe_const0, pipe_const1, pipe_const2])
     output = next(pipe_merge.out)
     expected = ['test', 'test', 'test']
     self.assertTrue(output == expected, msg=utg.errmsg(output, expected))
Esempio n. 2
0
 def test_stack_tensor(self):
     input1 = np.ones([3, 3])
     input2 = np.ones([4, 4]) * 2
     pipe_input1 = utp.Inputer(input1)
     pipe_input2 = utp.Inputer(input2)
     pipe_stack = utp.Pipe([pipe_input1, pipe_input2])
     output = next(pipe_stack.out)
     expect = [input1, input2]
     self.assertTrue(output == expect, msg=utg.errmsg(output, expect))
Esempio n. 3
0
 def test_gray(self):
     pipe_a = utp.Inputer(np.ones([1, 10, 10, 1]))
     pipe_b = utp.Inputer(np.zeros([1, 10, 10, 1]))
     pipe_merge = utp.Pipe([pipe_a, pipe_b])
     pipe_stacker = utp.TensorStacker(pipe_merge)
     stacked = next(pipe_stacker.out)
     output = stacked.shape
     expect = (2, 10, 10, 1)
     self.assertTrue(output == expect, msg=utg.errmsg(output, expect))
Esempio n. 4
0
    def test_gray2(self):
        data_file = os.path.join(TEST_DATA_PATH, 'img000000001.npy')
        imgrgb = np.array(np.load(data_file))
        imggray = imgrgb[:, :, 0]
        imgin = np.reshape(imggray, [1, 288, 352, 1])

        pipe_a = utp.Inputer(imgin)
        pipe_b = utp.Inputer(imgin)
        pipe_merge = utp.Pipe([pipe_a, pipe_b])
        pipe_stacker = utp.TensorStacker(pipe_merge)
        stacked = next(pipe_stacker.out)
        output = stacked.shape
        expect = (2, 288, 352, 1)
        self.assertTrue(output == expect, msg=utg.errmsg(output, expect))
Esempio n. 5
0
    def test_auto_after_stacker(self):
        data_file = os.path.join(TEST_DATA_PATH, 'img000000001.npy')
        imgrgb = np.array(np.load(data_file))
        imgin = np.reshape(imgrgb, [1, 288, 352, 3])

        pipe_a = utp.Inputer(imgin)
        pipe_b = utp.Inputer(imgin)

        pipe_merge = utp.Pipe([pipe_a, pipe_b])
        pipe_stacker = utp.TensorStacker(pipe_merge)
        pipe_tensor = utp.TensorFormater(pipe_stacker)
        tensor = next(pipe_tensor.out)
        output = tensor.shape
        expect = (2, 288, 352, 3)
        self.assertTrue(output == expect, msg=utg.errmsg(output, expect))
Esempio n. 6
0
 def test_set_copy_number(self):
     pipe_input = utp.Inputer(item='test')
     pipe_copy = utp.Copyer(pipe_input)
     pipe_copy.copy_number = 3
     output = [item for item in pipe_copy.out]
     expected = ['test', 'test', 'test']
     self.assertTrue(output == expected, msg=utg.errmsg(output, expected))
Esempio n. 7
0
 def test_basic(self):
     pipe_input = utp.Inputer(item='test', const_output=True)
     output = []
     for i in xrange(3):
         output.append(next(pipe_input.out))
     expected = ['test', 'test', 'test']
     self.assertTrue(output == expected, msg=utg.errmsg(output, expected))
Esempio n. 8
0
 def test_item(self):
     pipe_input = utp.Inputer()
     pipe_input.insert('test1')
     pipe_input.insert('test2')
     pipe_input.insert('test3')
     output = [item for item in pipe_input.out]
     expected = ['test1', 'test2', 'test3']
     self.assertTrue(output == expected, msg=utg.errmsg(output, expected))
Esempio n. 9
0
 def test_auto_imgrgb(self):
     data_file = os.path.join(TEST_DATA_PATH, 'img000000001.npy')
     imgrgb = np.array(np.load(data_file))
     shapergb = imgrgb.shape
     pipe_input = utp.Inputer(imgrgb)
     pipe_formater = utp.TensorFormater(pipe_input)
     imgtensor = next(pipe_formater.out)
     output = imgtensor.shape
     expect = [1] + list(shapergb)
     expect = tuple(expect)
     self.assertTrue(output == expect, msg=utg.errmsg(output, expect))
Esempio n. 10
0
    def test_auto_stacked_image(self):
        data_file = os.path.join(TEST_DATA_PATH, 'img000000001.npy')
        imgrgb = np.array(np.load(data_file))
        input_ = np.zeros(
            [2, imgrgb.shape[0], imgrgb.shape[1], imgrgb.shape[2]])
        input_[0, :, :, :] = imgrgb
        input_[1, :, :, :] = imgrgb

        pipe_input = utp.Inputer(input_)
        pipe_tensor = utp.TensorFormater(pipe_input)
        tensor = next(pipe_tensor.out)
        output = tensor.shape
        expect = (2, 288, 352, 3)
        self.assertTrue(output == expect, msg=utg.errmsg(output, expect))
Esempio n. 11
0
    def _prepare(self):
        super(DataSetSuperResolution, self)._prepare()
        if not self._is_lock:
            data_filename_iter = utp.FileNameLooper(
                self._path_data,
                prefix=self._prefix_data,
                random_shuffle=self._is_shuffle,
                ids=self._ids,
                max_epoch=self._epoch_max)
            self._filename_iter = data_filename_iter
        else:
            self._filename_iter = utp.FileNameLooper(self._path_data,
                                                     prefix=self._prefix_data,
                                                     random_shuffle=False,
                                                     ids=self._ids,
                                                     max_epoch=1)
            data_filename_iter = utp.Inputer()
            self._filename_inputer = data_filename_iter
            self._is_next_file = True
        if self._is_single:
            data_image = utp.NPYReaderSingle(data_filename_iter)
            data_image_copyer = utp.Copyer(data_image, copy_number=2)
            data_tensor = utp.TensorFormater(data_image_copyer)
            label_tensor = utp.TensorFormater(data_image_copyer)
        else:
            data_filename_copyer = utp.Copyer(data_filename_iter,
                                              copy_number=2)
            label_filename = utp.LabelFinder(data_filename_copyer,
                                             utg.label_name)
            data_filename = utp.Pipe(data_filename_copyer)
            data_image = utp.NPYReaderSingle(data_filename)
            label_image = utp.NPYReaderSingle(label_filename)
            data_tensor = utp.TensorFormater(data_image)
            label_tensor = utp.TensorFormater(label_image)
        if self._is_need_gray:
            data_full = utp.ImageGrayer(data_tensor)
            label_full = utp.ImageGrayer(label_tensor)
        else:
            data_full = data_tensor
            label_full = label_tensor

        merge = utp.Pipe([data_full, label_full])
        stacker = utp.TensorStacker(merge)
        multi_tensor = utp.TensorFormater(stacker)
        stacked_shape = [2] + list(self._shape_o)
        patch_generator = utp.PatchGenerator(multi_tensor,
                                             shape=stacked_shape,
                                             n_patches=self._n_patches,
                                             strides=self._strides,
                                             random_gen=self._is_shuffle,
                                             check_all=self._is_check_all)
        buffer_stacked = utp.Buffer(patch_generator)

        slicer = utp.TensorSlicer(buffer_stacked, self._shape_sample_o)
        buffer_hl = utp.Buffer(slicer)
        self._label = utp.TensorFormater(buffer_hl)
        down_sample = utp.DownSampler(buffer_hl,
                                      self._down_sample_ratio,
                                      method=self._down_sample_method)
        self._data = utp.TensorFormater(down_sample)
        self._testo = self._filename_iter
        self._means = []
        self._stds = []