def main(): train_alignment, train_reviews = getdata.readFiles("train.npz") train_alignment = getdata.decode(train_alignment) # train_alignment = getdata.describeLabels(train_alignment) train_reviews = getdata.decode(train_reviews) test_align, test_reviews = getdata.readFiles("test.npz") test_align = getdata.decode(test_align) # test_align = getdata.describeLabels(test_align) test_reviews = getdata.decode(test_reviews) model = analyze.train(train_reviews, test_reviews, train_alignment) # analyze.predict(test_reviews,model) analyze.predict(test_reviews, test_align, model)
def set_d(file, Kernel, df, df1): cons = 1.19 eps = 0.008 gam = 0.707 p=1 predict(df, Kernel, cons, eps, p, gam, "ARCHITECTURE2") predict(df1, Kernel, cons, eps, p, gam, "ARCHITECTURE1") print("====================================================")
async def receiver(websocket, path): """ Socket that handles segmentation and predict queries INPUT: websocket - the tcp connection path - path to the image OUTPUT: none (except this function sends result back to nodejs client) """ jsonString = await websocket.recv() jsonObject = json.loads(jsonString) print(jsonObject["type"]) if (jsonObject["type"] == "segmentation"): filename = jsonObject["filename"] path = "../communication/rawimage/" + filename norm_points = segmentation(path) obj = { "type": "segmentation", "boxes": norm_points, "iou": 0.65, } string = json.dumps(obj) await websocket.send(string) if (jsonObject["type"] == "predict"): filename = jsonObject["filename"] path = "../communication/rawimage/" + filename global model norm_points, labels, percentages = predict(model, path) print("done") obj = { "type": "predict", "boxes": norm_points, "labels": labels, } string = json.dumps(obj) print("sent") await websocket.send(string)
def set_e(file, Kernel, df, df1): cons = 1.00 eps = 0.011 gam = 0.841 p=1 predict(df, Kernel, cons, eps, p, gam, "ARCHITECTURE2") predict(df1, Kernel, cons, eps, p, gam, "ARCHITECTURE1") print("====================================================")
def set_a(file, Kernel, df, df1): cons = 26.91 eps = 0.0004 gam = 0.105 p=1 predict(df, Kernel, cons, eps, p, gam, "ARCHITECTURE2") predict(df1, Kernel, cons, eps, p, gam, "ARCHITECTURE1") print("====================================================")
def set_c(file, Kernel, df, df1): cons = 1.41 eps = 0.006 gam = 0.297 p=1 #validate(df, Kernel, cons, eps, p, gam) predict(df, Kernel, cons, eps, p, gam, "ARCHITECTURE2") predict(df1, Kernel, cons, eps, p, gam, "ARCHITECTURE1") print("====================================================")
def set_f(file, Kernel, df, df1): cons = 1.00 eps = 0.011 gam = 0.189 p=1 #validate(df, Kernel, cons, eps, p, gam) predict(df, Kernel, cons, eps, p, gam, "ARCHITECTURE2") predict(df1, Kernel, cons, eps, p, gam, "ARCHITECTURE1") print("====================================================")
inputs, targets = dataset() model.train() optimizer.zero_grad() x = torch.tensor(inputs).to(device) y = torch.tensor(targets).to(device) logits, (state_h, state_c) = model(x, (state_h, state_c)) loss = criterion(logits.transpose(1, 2), y) loss_value = loss.item() loss.backward() state_h = state_h.detach() state_c = state_c.detach() torch.nn.utils.clip_grad_norm_(model.parameters(), flags.gradients_norm) optimizer.step() if iterator % 100 == 0: print('Epoch: {}/{}'.format(epoch, flags.epochs), 'Iteration: {}'.format(iterator), 'Loss: {}'.format(loss_value)) if iterator % (epoch * flags.max_batch) == 0: predict(device, model, dataset.vocabulary, top_k=5) torch.save(model.state_dict(), 'LSTM-word-level/states_testing/epoch-{}.pth'.format(epoch))