Exemplo n.º 1
0
    def execute(self, model_simi: BaseModel):
        model = ModelFactory.get_model(self.model_type)
        if os.path.isfile(self.model_path):
            model.load_model(self.model_path)
            return model

        sal_data = None

        for i, path in enumerate(self.img_path):
            im_data = self.parse_data(self.img_data[i],
                                      self.img_data_level0[i], model_simi)
            for j, rlist in enumerate(im_data.rlists):
                data = Region2Csv.generate_seg_csv(rlist,
                                                   im_data.feature93s[j],
                                                   self.seg_path[i])
                if data is None:
                    continue
                if sal_data is None:
                    sal_data = data
                else:
                    sal_data = np.vstack((sal_data, data))
        y_train, x_train = self.prepare_data(sal_data)

        model.train(x_train, y_train)
        model.save_model(self.model_path)
        return model
Exemplo n.º 2
0
    def execute(self):
        model = ModelFactory.get_model(model_name=self.model_type)
        if os.path.isfile(self.model_path):
            model.load_model(self.model_path)
            return model

        simi_data = None
        for i, path in enumerate(self.img_path):
            im_data = self.check_exist(
                img_path=self.img_path[i], img_path_level0=self.img_data_level0[i]
            )

            data = Region2Csv.generate_similar_csv(
                im_data.rlist, im_data.comb_features, self.seg_path[i]
            )
            if simi_data is None:
                simi_data = data
            else:
                simi_data = np.vstack((simi_data, data))
            logging.info("Finished simi {}".format(i))

        y_train, x_train = self.prepare_data(simi_data)

        model.train(x_train, y_train)
        model.save_model(self.model_path)
        return model
Exemplo n.º 3
0
    def execute(self, model_sal):
        model = ModelFactory.get_model(self.model_type)
        if os.path.isfile(self.model_path):
            model.load_model(self.model_path)
            return model
        ground_truths = None
        salience_maps = None

        for i, path in enumerate(self.img_data):
            im_data = pickle.load(open(path, "rb+"))
            seg_num = len(im_data.rlists)
            if seg_num < len(self.C_LIST) + 1:
                continue

            height = im_data.rmat.shape[0]
            width = im_data.rmat.shape[1]
            salience_map = np.zeros([seg_num, height, width])
            for j, rlist in enumerate(im_data.rlists):
                Y = model_sal.predict(im_data.feature93s[j])[:, 1]
                for k, r in enumerate(rlist):
                    salience_map[j][r] = Y[k]
            ground_truth = cv2.imread(self.seg_path[i])[:, :, 0]
            ground_truth[ground_truth == 255] = 1
            if salience_maps is None:
                salience_maps = salience_map.reshape([-1, height * width]).T
            else:
                salience_maps = np.append(salience_maps,
                                          salience_map.reshape(
                                              [-1, height * width]).T,
                                          axis=0)
            if ground_truths is None:
                ground_truths = ground_truth.reshape(-1)
            else:
                ground_truths = np.append(ground_truths,
                                          ground_truth.reshape(-1),
                                          axis=0)
        x_train = salience_maps
        y_train = ground_truths
        model.train(x_train, y_train)
        model.save_model(self.model_path)
Exemplo n.º 4
0
 def get_model(self):
     model = ModelFactory.get_model(self.model_type)
     model.load_model(self.model_path)
     return model
Exemplo n.º 5
0
def build_model(problem_name, observation_shape, num_actions, model_params):
    # Model
    model_manager = ModelFactory(problem_name, observation_shape, num_actions, model_params)
    model = model_manager.get_model()
    return model