print('# Test Set Obs: ', len(obs)) #######################START: INSERT CODE HERE################################# # Produce Scores for a Set of Matching and Set of Non-Matching Pairs x0 = [] # list of datapoints to pass to model p0 = [] x1 = [] # list of datapoints to pass to model p1 = [] for i in range(len(obs)): for j in range(len(obs)): if i != j: d = [obs[i][:], obs[j][:]] # datapoint consisting of pair of observations datapoint = trnMod.augmentAndVectorize(d) if tags[i] != tags[j]: x0.append(datapoint) else: x1.append(datapoint) print('i', i) if len(x0) > 0: y0 = model(torch.FloatTensor(x0, device=device)) x0 = [] p0tmp = [list(np.exp(q.detach().cpu().numpy()))[0] for q in y0] p0 += p0tmp if len(x1) > 0: y1 = model(torch.FloatTensor(x1, device=device)) x1 = [] p1tmp = [list(np.exp(q.detach().cpu().numpy()))[0] for q in y1]
pairs = [] labels = [] # Grab Given Number of Examples of Non Match while len(pairs) < 3: i = int(random.uniform(0, len(obs))) j = int(random.uniform(0, len(obs))) if i != j: if tags[i] != tags[j]: pairs.append((i, j)) labels.append([1]) # Grab Given Number of Examples of Match while len(pairs) < 5: i = int(random.uniform(0, len(obs))) j = int(random.uniform(0, len(obs))) if i != j: if tags[i] == tags[j]: pairs.append((i, j)) labels.append([0]) inputs = [] for i, j in pairs: datapoint = trnMod.augmentAndVectorize([obs[i][:], obs[j][:]]) inputs.append(datapoint) inputs = np.array(inputs) labels = np.array(labels) print('inputs', inputs.shape) show_saliency_maps(inputs, labels)
obs, tags = trnMod.loadDataTags(test_data, test_tags) print('# Test Set Obs: ', len(obs)) print('# Unique RSOs: ', len(set(tags))) # Produce Scores for a Set of Matching and Set of Non-Matching Pairs c = [] rsos = [] for i in range(len(obs)): #for i in range(119,122): p = {} #Dictionary of Scores temp = [] k = [] for j in range(len(obs)): if i != j: datapoint = trnMod.augmentAndVectorize([obs[i][:], obs[j][:]]) else: datapoint = trnMod.augmentAndVectorize([obs[0][:], obs[-1][:]]) #dummy temp.append(datapoint) y = model(torch.FloatTensor(temp, device=device)) y = [list(np.exp(q.detach().cpu().numpy()))[0] for q in y] y[i] = 0 for q in range(len(y)): if 1-y[q] < costMax: k.append(q) #print('k', len(k)) if len(k) >= numObs: #Add to Dictionary