def main(modelfile: str, features: List[float], print_results: bool = True) -> List[Dict[str, Any]]: """ Evaluate the model described in ``modelfile`` with ``inputvec`` as input data. Parameters ---------- features : List[float] print_results : bool Print results if True. Always return results. Returns ------- List of possible answers, reverse-sorted by probability. """ model = utils.get_model(modelfile) if not model: return [] x = np.array([features]) model_output = get_model_output(model, x) results = get_results(model_output, model["outputs"]) if print_results: show_results(results, n=10) return results
def main(model_file, test_data, verbose=True): """ Evaluate a model Parameters ---------- model_file : string Path to a model file test_data : string Path to a testdata.tar file Returns ------- Testing results """ model = utils.get_model(model_file) data = utils.get_data(test_data) if data is None: logging.error("Data could not be loaded. Stop testing.") return x_vec, y_vec = data correct = 0 total = 0 for x, y in zip(x_vec, y_vec): x = numpy.array([x]) y_pred = evaluate.get_model_output(model, x) y_pred = numpy.argmax(y_pred) if y_pred == y[0]: correct += 1 total += 1 if verbose and total % 100 == 0: print("%i: %0.2f" % (total, float(correct)/total)) print("Correct: %i/%i = %0.2f of total correct" % (correct, total, float(correct)/total)) return float(correct)/total
def main(model_file: str, test_data: str, verbose=True) -> float: """ Evaluate a model Parameters ---------- model_file : str Path to a model file test_data : str Path to a testdata.hdf5 file Returns ------- Testing results """ model = utils.get_model(model_file) data = utils.get_data(test_data) x_vec, y_vec = data correct = 0 total = 0 for x, y in zip(x_vec, y_vec): x = numpy.array([x]) y_pred = evaluate.get_model_output(model, x) y_pred = numpy.argmax(y_pred) if y_pred == y[0]: correct += 1 total += 1 if verbose and total % 100 == 0: print("%i: %0.2f" % (total, float(correct) / total)) print("Correct: %i/%i = %0.2f of total correct" % (correct, total, float(correct) / total)) return float(correct) / total
def main(model_file, test_data, verbose=True): """ Evaluate a model Parameters ---------- model_file : string Path to a model file test_data : string Path to a testdata.tar file Returns ------- Testing results """ model = utils.get_model(model_file) data = utils.get_data(test_data) if data is None: logging.error("Data could not be loaded. Stop testing.") return x_vec, y_vec = data correct = 0 total = 0 for x, y in zip(x_vec, y_vec): x = numpy.array([x]) y_pred = evaluate.get_model_output(model, x) y_pred = numpy.argmax(y_pred) if y_pred == y[0]: correct += 1 total += 1 if verbose and total % 100 == 0: print("%i: %0.2f" % (total, float(correct) / total)) print("Correct: %i/%i = %0.2f of total correct" % (correct, total, float(correct) / total)) return float(correct) / total
def main(model_file, model_output_file, training_data, batch_size, learning_rate, epochs): """Train model_file with training_data.""" data = utils.get_data(training_data) if data is None: logging.error("Data could not be loaded. Stop training.") return x, y = data assert y is not None model = utils.get_model(model_file) minibatch_gradient_descent(model, x, y, batch_size, learning_rate, epochs) utils.write_model(model, model_output_file)
def main(modelfile, features, print_results=True): """Evaluate the model described in ``modelfile`` with ``inputvec`` as input data. Parameters ---------- features : list of floats print_results : bool Print results if True. Always return results. Returns ------- List of possible answers, reverse-sorted by probability. """ model = utils.get_model(modelfile) if not model: return [] x = numpy.array([features]) model_output = get_model_output(model, x) results = get_results(model_output, model['outputs']) if print_results: show_results(results, n=10) return results