# get language scores and embeddings for lang_id in range(n_lang): this_lang = config.main_dev_language_list[lang_id] embs1, ids1 = [], [] embs2, ids2 = [], [] with torch.no_grad(): for batch in datasets[lang_id].loader: ids = batch.pop("ids") inv = batch.pop("inv") out1, out2 = net.forward(batch, numpy=True) ids1.append(ids[inv.numpy()]) ids2.append(ids) embs1.append(out1) embs2.append(out2) ids1 = np.hstack(ids1) ids2, ind = np.unique(np.hstack(ids2), return_index=True) embs1 = np.vstack(embs1) embs2 = np.vstack(embs2)[ind] acoustic_ap = metric.acoustic_ap(embs1, ids1) crossview_ap = metric.crossview_ap(embs1, ids1, embs2, ids2) log.info(f"language = {this_lang},"
''' Start Testing ''' if opt.test_dataset_name == 'all': num_test_samples = get_size_all(opt) else: num_test_samples = get_size_dataset(opt, opt.train_dataset_name) niter = int(np.floor(1.0 * num_test_samples / opt.test_batch_size)) correct_cnt = 0 total_cnt = 0 labels_all = [] preds_all = [] for iter in range(niter): net.forward() # switch final layer name if opt.model_name == 'VggFace': pred_layer_name = 'fc9_face' elif opt.model_name == 'ResNet50' or opt.model_name == 'ResNet18': pred_layer_name = 'fc_face2' elif opt.model_name == 'SqueezeNet': pred_layer_name = 'fc_face' preds = net.blobs[pred_layer_name].data.argmax(axis=1) labels = np.ndarray.flatten(net.blobs['label'].data) preds_all += preds.tolist() labels_all += labels.tolist()
content[y][x] = max( content[y][x], sqrt(min(1, max(0, 1 * (0.8 - abs(dist)))))) pygame.draw.rect(screen, [ content[y][x] * 255, content[y][x] * 255, content[y][x] * 255 ], (1 + x * scale, 1 + y * scale, scale, scale)) if test or True: X = [] for y in range(size): for x in range(size): X.append(content[y][x]) X = np.reshape(np.array(X).T, (256, 1)) cache = net.forward(X, parameters) L = len(parameters) // 2 result = cache['A' + str(L)].T[0] # print("Chosen: ", np.argmax(result)) myfont = pygame.font.SysFont("monospace", 30) for i in range(classes): label = myfont.render(str(i) + ":", 1, (0, 0, 0)) res = myfont.render( str(int(10000 * max(0, min(1, result[i]))) / 100) + "%", 1, (200, 20, 20) if i == np.argmax(result) else (0, 0, 0)) screen.blit(label, (250, 10 + i * 35)) screen.blit(res, (350, 10 + i * 35))