Пример #1
0
    def __init__(self,
                 sketch_data_npy="./data/sketch/sketch_paths_class.npy",
                 sketch_train_image_npy="./data/sketch/sketch_train_image.npy",
                 sketch_test_image_npy="./data/sketch/sketch_test_image.npy",
                 sketch_train_label_npy="./data/sketch/sketch_train_label.npy",
                 sketch_test_label_npy="./data/sketch/sketch_test_label.npy",
                 train_test_ratio=5,
                 pre_process=Tools.pre_process_input,
                 target_size=128,
                 re_data=False):

        # 网络输入大小
        self.input_shape = [target_size, target_size, 1]
        Tools.print("image shape is {}".format(self.input_shape))

        # 如果不存在或者重新生成数据
        if not os.path.exists(sketch_train_image_npy) or re_data:
            # 读取图片路径和标签
            Tools.print("data not exist and produce data...")
            (self._sketch_train_image_path, self._sketch_train_label,
             self._sketch_test_image_path,
             self._sketch_test_label) = self._read_sketch_path(
                 sketch_data_npy, train_test_ratio)

            # 读取数据
            Tools.print("read data...")
            self._sketch_train_image = self._read_data(
                self._sketch_train_image_path, pre_process, target_size)
            self._sketch_test_image = self._read_data(
                self._sketch_test_image_path, pre_process, target_size)

            # 保存
            Tools.print("save data...")
            np.save(sketch_train_image_npy, self._sketch_train_image)
            np.save(sketch_test_image_npy, self._sketch_test_image)
            np.save(sketch_train_label_npy, self._sketch_train_label)
            np.save(sketch_test_label_npy, self._sketch_test_label)
            Tools.print("data save ok")
        else:
            Tools.print("data exist and load data...")
            self._sketch_train_image = np.load(sketch_train_image_npy)
            self._sketch_test_image = np.load(sketch_test_image_npy)
            self._sketch_train_label = np.load(sketch_train_label_npy)
            self._sketch_test_label = np.load(sketch_test_label_npy)
            Tools.print("data load ok")
            pass

        # 类别数
        self.class_num = self._sketch_train_label.max() + 1
        Tools.print("class num is {}".format(self.class_num))
        pass