示例#1
0
def validate(crf, validate_data_true_label, validate_loader, val_dataset_size,
             device):
    all_predictions = []
    for image_batch, data_ids, _ in validate_loader:
        all_predictions.extend(crf.make_predictions(image_batch).cpu().numpy())
    all_predictions = np.squeeze(np.array(all_predictions))
    return mapk(actual=validate_data_true_label,
                predicted=parse_validation_data_labels(all_predictions),
                k=3)
示例#2
0
 def get_val_acc(self):
     predictions = []
     for i, val_data in self.cur_val_data_fold.iterrows():
         val_data = build_feature.set_feature_mat(val_data['drawing'], 256)
         prediction = np.exp(self.weights @ val_data)
         prediction = np.argsort(prediction)
         predictions.append(prediction[-3:])
     return mapk(actual=np.matrix(
         np.ones(self.cur_val_data_size, dtype=np.int8) * self.cur_cat),
                 predicted=np.array(predictions),
                 k=3)
示例#3
0
def validate(resnet, validate_data_true_label, validate_loader,
             val_dataset_size, device):
    all_predictions = []
    resnet.eval()
    for image_batch, _ in validate_loader:
        image_batch = image_batch.to(device)
        outputs = resnet(image_batch)
        _, predicted = torch.topk(outputs.data, 3)
        all_predictions.extend(predicted.cpu().numpy())
    all_predictions = np.squeeze(np.array(all_predictions))
    return mapk(actual=validate_data_true_label,
                predicted=parse_validation_data_labels(all_predictions),
                k=3)
 def get_val_acc(self, val_sess, predictions_i, feat_i_ph, weights_ph,
                 weights):
     predictions = []
     for data_id in self.cur_val_fold_seq:
         val_data = build_feature.set_feature_mat(
             self.cur_val_data_fold.loc[data_id, 'drawing'])
         predictions.append(
             val_sess.run(predictions_i,
                          feed_dict={
                              feat_i_ph: val_data,
                              weights_ph: weights
                          }))
     return mapk(actual=np.matrix(
         np.ones((self.num_val_data), dtype=np.int8) * self.cur_cat),
                 predicted=np.array(predictions),
                 k=3)