(reference_city, target_city, Encoder, Classifier, epoch_num)
| 7 | from tqdm import tqdm |
| 8 | |
| 9 | def evaluate(reference_city, target_city, Encoder, Classifier, epoch_num): |
| 10 | Target_eval = City_Dataset(dataset_type='eval', city_name=target_city) |
| 11 | Target_eval_loader = DataLoader(dataset=Target_eval) |
| 12 | |
| 13 | # load model param |
| 14 | root_path = os.path.dirname(os.path.realpath(__file__)) |
| 15 | save_path = root_path + '/../model/ref_' + reference_city + '_epoch' + str(epoch_num) + '/' |
| 16 | encoder = Encoder() |
| 17 | classifier = Classifier() |
| 18 | encoder_state_dict = paddle.load(save_path + 'encoder.pdparams') |
| 19 | encoder.set_state_dict(encoder_state_dict) |
| 20 | classifier_state_dict = paddle.load(save_path + 'classifier.pdparams') |
| 21 | classifier.set_state_dict(classifier_state_dict) |
| 22 | encoder.eval() |
| 23 | classifier.eval() |
| 24 | |
| 25 | auc = paddle.metric.Auc() |
| 26 | for features_T, y_T in tqdm(Target_eval_loader()): |
| 27 | features_T, y_T = paddle.cast(features_T, dtype='float32'), paddle.cast(y_T, dtype='float32') |
| 28 | encoded_T = encoder(features_T) |
| 29 | clf_T = classifier(encoded_T) |
| 30 | pred_T = np.concatenate((1-clf_T.numpy(), clf_T.numpy()), axis=1) |
| 31 | y_T = paddle.reshape(y_T, [-1, 1]).numpy() |
| 32 | auc.update(preds=pred_T, labels=y_T) |
| 33 | auc_value = auc.accumulate() |
| 34 | print("AUC:{}".format(auc_value)) |
| 35 | |
| 36 | if __name__ == '__main__': |
| 37 | parser = argparse.ArgumentParser(description="evaluate c-watcher on target city.") |
no test coverage detected