# Pastebin BZAX3Ouv def evaluate_dataset(eval_job, dataset_dir, storage_dir): db.dataset_eval.set_job_status(eval_job["id"], db.dataset_eval.STATUS_RUNNING) eval_location = os.path.join(os.path.abspath(dataset_dir), eval_job["id"]) utils.path.create_path(eval_location) temp_dir = tempfile.mkdtemp() try: snapshot = db.dataset.get_snapshot(eval_job["snapshot_id"]) train, test = artistfilter.filter(eval_job["snapshot_id"], eval_job["options"]) db.dataset_eval.add_sets_to_job(eval_job["id"], train, test) logging.info("Generating filelist.yaml and copying low-level data for evaluation...") filelist_path = os.path.join(eval_location, "filelist.yaml") filelist = dump_lowlevel_data(train.keys(), temp_dir) with open(filelist_path, "w") as f: yaml.dump(filelist, f) logging.info("Generating groundtruth.yaml...") groundtruth_path = os.path.join(eval_location, "groundtruth.yaml") with open(groundtruth_path, "w") as f: yaml.dump(create_groundtruth_dict(snapshot["data"]["name"], train), f) logging.info("Training GAIA model...") evaluate_gaia(eval_job["options"], eval_location, groundtruth_path, filelist_path, storage_dir, eval_job) db.dataset_eval.set_job_status(eval_job["id"], db.dataset_eval.STATUS_DONE) logging.info("Evaluation job %s has been completed." % eval_job["id"]) # TODO(roman): Also need to catch exceptions from Gaia. except db.exceptions.DatabaseException as e: logging.info("Evaluation job %s has failed!" % eval_job["id"]) db.dataset_eval.set_job_status( job_id=eval_job["id"], status=db.dataset_eval.STATUS_FAILED, status_msg=str(e), ) logging.info(e) finally: # Clean up the source files used to generate this model. # We can recreate them from the database if we need them # at a later stage. shutil.rmtree(temp_dir) def evaluate_gaia(options, eval_location, groundtruth_path, filelist_path, storage_dir, eval_job): results = gaia_wrapper.train_model( project_dir=eval_location, groundtruth_file=groundtruth_path, filelist_file=filelist_path, c_values=options.get("c_values", []), gamma_values=options.get("gamma_values", []), preprocessing_values=options.get("preprocessing_values", []), ) logging.info("Saving results...") save_history_file(storage_dir, results["history_path"], eval_job["id"]) db.dataset_eval.set_job_result(eval_job["id"], json.dumps({ "project_path": eval_location, "parameters": results["parameters"], "accuracy": results["accuracy"], "confusion_matrix": results["confusion_matrix"], "history_path": results["history_path"], })) def evaluate_sklearn(eval_location, groundtruth_path, filelist_path, storage_dir, eval_job): # create_classification_project(ground_truth_directory=groundtruth_path) pass