def activate(self): pred = predict(self.inputs, self.weights) if self.activation_function: pred = self.activation_function(pred) + self.bias self.inputs = [None] * len(self.inputs) for cb in self.observers: cb(pred)
def simple_case(): features = [1.0, 3.0, 2.0] weights = [0, 0, 0] goal_pred = 10.0 alpha = 1e-2 times = 100 print(f"goal_prediction={goal_pred}") label = predict(features, weights) print(f"*Before training*") print(f"prediction={label}") print(f"*After training*") weights = train(features, weights, goal_pred, times, alpha) label = predict(features, weights) print(f"prediction={label}") print(f"confidence={round(100-(abs(label-goal_pred))*100/(label+goal_pred), 2)}%") print(f"weights={weights}")
def main(): model=base.loadchkpnt(path) with open('cat_to_name.json', 'r') as jfil: cat_to_name = json.load(jfil) probs = base.predict(image_path, model, topk, gpu) classes = [cat_to_name[str(ix + 1)] for ix in np.array(probs[1][0])] probability = np.array(probs[0][0]) i=0 while i < topk: print("{} has probability: {}".format(classes[i], probability[i])) i += 1
def do_single(r): global training_x, training_y, testing_x, testing_y wl1, wl2 = doTrain(_g_M, _g_eta, r, _g_T, training_x.copy(), training_y.copy()) eout = predict(wl1, wl2, testing_x.copy(), testing_y.copy()) print "r:", r, ", eout:", eout return r, eout
default='cat_to_name.json') ap.add_argument( 'image_path', default='/home/workspace/ImageClassifier/flowers/test/1/image_06752.jpg', nargs='*', action="store", type=str) inputs = ap.parse_args() image_path = inputs.image_path topk = inputs.top_k device = inputs.gpu path = inputs.checkpoint dataloaders, image_datasets = base.load_data() model = base.load_checkpoint(path) base.testdata_acc(model, dataloaders, image_datasets, 'test', True) with open('cat_to_name.json', 'r') as json_file: cat_to_name = json.load(json_file) img_tensor = base.process_image(image_path) probs = base.predict(image_path, model, topk) print("Image Directory: ", image_path) print("Predictions probabilities: ", probs)
def do_single(M): global training_x, training_y, testing_x, testing_y wl1, wl2 = doTrain(M, _g_eta, _g_w_value_range, _g_T, training_x.copy(), training_y.copy()) eout = predict(wl1, wl2, testing_x.copy(), testing_y.copy()) return M, eout