def run(self): self.output = make_output_folder(self.input, self.output, self.force) train() if self.input is not None: model = get_model() from fifty.commands.whatis import WhatIs classifier = WhatIs(self.args) gen_files = read_files(self.input, self.block_size, self.recursive) try: while True: file, file_name = next(gen_files) pred_probability = classifier.infer(model, file) classifier.output_predictions(pred_probability, file_name) del file, file_name except: pass else: print('No input file given for inference on trained model.') return
def run(self): if self.input is None: raise Exception("Input not provided, please see usage") if self.verbose >= 1: self.output = make_output_folder(self.input, self.output, self.force) model = self.get_model() gen_files = read_files(self.input, self.block_size, self.recursive) if self.verbose >= 2: print('Predicting..... Please be patient!') try: while True: file, file_name = next(gen_files) pred_probability = self.infer(model, file) self.output_predictions(pred_probability, file_name) del file, file_name except Exception as e: print(e) if self.verbose >= 2: print('Prediction Complete!') return
def run(self): if self.input is None: parser.print_usage() sys.exit(1) if self.verbose >= 1: self.output = make_output_folder(self.input, self.output, self.force) model = self.get_model() gen_files = read_files(self.input, self.block_size, self.recursive) if self.verbose >= 2: print('Predicting..... Please be patient!') try: while True: file, file_name = next(gen_files) pred_probability = self.infer(model, file) self.output_predictions(pred_probability, file_name) del file, file_name except: pass if self.verbose >= 2: print('Prediction Complete!') return
def run(self): self.output = make_output_folder(self.input, self.output, self.force) self.train_model() if self.input is None: raise Exception( 'No input blocks given for inference on trained model.') model = self.get_model() print('evaluating model...') gen_files = read_files(self.input, self.block_size, self.recursive) if self.is_train_autoencoder: try: start_time = time.time() for i, (blocks, file_name) in enumerate(gen_files): # keep only 1/100 of the elements (for performance) blocks = blocks[:int(np.ceil(len(blocks) * 0.01))] print('loaded files in\t{:.2f}s.\t'.format(time.time() - start_time), end='') time_ = time.time() output = model.predict(blocks) print('predicted in\t{:.2f}s.\t'.format(time.time() - time_), end='') time_ = time.time() # flattening plt.plot(blocks.flatten(), label='input', alpha=0.7, linewidth=0.5) plt.plot(output.flatten(), label='output', alpha=0.7, linewidth=0.5) plt.title(f'Autoencoder reconstruction {i}') plt.xlabel(f'Byte index') plt.ylabel(f'Byte value') plt.legend(loc='upper right') plt.savefig( os.path.join(self.model_dir(), f'reconstruction_{i}_{time.time()}.png')) plt.show() print('plotted in\t{:.2f}s, total time:\t{:.2f}s'.format( time.time() - time_, time.time() - start_time)) del blocks, file_name start_time = time.time() except Exception as e: print("!Error encountered while predicting: " + str(e)) import traceback traceback.print_exc() else: from fifty.commands.whatis import WhatIs classifier = WhatIs(self.options, *self.args) try: start_time = time.time() for blocks, file_name in gen_files: print('loaded files in\t{:.2f}s.\t'.format(time.time() - start_time), end='') time_ = time.time() pred_probability = classifier.infer(model, blocks) print('predicted in\t{:.2f}s.\t'.format(time.time() - time_), end='') time_ = time.time() classifier.output_predictions(pred_probability, file_name) print('plotted in\t{:.2f}s, total time:\t{:.2f}s'.format( time.time() - time_, time.time() - start_time)) del blocks, file_name start_time = time.time() except Exception as e: print("!Error encountered while predicting: " + str(e)) import traceback traceback.print_exc()