def run_test(self): """ 如果数据不是csv,可以重载这个函数,转为df :return: """ if self.test_path is None: self.log.warning('test path is empty, set path in .yaml file firstly') return model_name = os.path.split(self.re_model_path)[-1] curr = Utility.timestamp2str_file() out_folder = model_name + curr if os.path.isdir(self.test_path): out_folder = os.path.join(self.test_path, out_folder) os.mkdir(out_folder) fs = os.listdir(self.test_path) for f in fs: out_path = os.path.join(out_folder, f) f = os.path.join(self.test_path, f) if os.path.isdir(f): continue self.log.info('input: {}'.format(f)) self.log.info('output: {}'.format(out_path)) df = pd.read_csv(f) self.test(df, out_path) elif os.path.isfile(self.test_path): fs = os.path.split(self.test_path) out_folder = os.path.join(fs[0], out_folder) os.mkdir(out_folder) out_path = os.path.join(out_folder, fs[-1]) self.log.info('input: {}'.format(self.test_path)) self.log.info('output: {}'.format(out_path)) df = pd.read_csv(self.test_path, lineterminator='\n') self.test(df, out_path)
def create_timestamp_folder(self, child='checkpoints'): """ 创建时间戳的文件夹,存放输出模型 :param child: :return: """ timestamp = Utility.timestamp2str_file() self.model_out_path = os.path.join(self.model_out_path, timestamp) if child is not None: self.checkpoint_path = os.path.join(self.model_out_path, child) else: self.checkpoint_path = self.model_out_path if not os.path.exists(self.checkpoint_path): os.makedirs(self.checkpoint_path) self.checkpoint_prefix = os.path.join(self.checkpoint_path, 'model')