Пример #1
0
 def train_file(self, file):
     self.start_new_file()
     if self.should_batch_process:
         try:
             binary_converter.read_data(file, self.process_pair_batch, batching=True)
         except Exception as e:
             print('error batch training on file ', e)
     else:
         try:
             binary_converter.read_data(file, self.process_pair, batching=False)
         except Exception as e:
             print('error training on file ', e)
     self.end_file()
Пример #2
0
    step = 0

    def __init__(self, game_file):
        self.game_file = game_file
        self.inputs = np.array([])
        self.outputs = np.array([])

    def process_pair(self, input_array, output_array, pair_number,
                     file_version):
        self.inputs = np.append(self.inputs, np.array(input_array))
        self.outputs = np.append(self.outputs, np.array(output_array))
        if self.inputs.shape[0] % 2000 == 0:
            binary_converter.write_array_to_file(self.game_file, self.inputs)
            binary_converter.write_array_to_file(self.game_file, self.outputs)
            self.inputs = np.array([])
            self.outputs = np.array([])
            self.step = 0
        self.step += 1


fs = glob.glob(os.path.join(args.path, '*.gz'))
if not os.path.isdir('converted/'):
    os.makedirs('converted/')
print(fs, args.path)
for file in fs:
    with gzip.open(file, 'rb') as f:
        with gzip.open(os.path.join('converted', os.path.basename(file)),
                       'wb') as new_file:
            trainer = ReplayConverter(new_file)
            binary_converter.read_data(f, trainer.process_pair)