MCPcopy Create free account
hub / github.com/PaddlePaddle/Research / evaluate

Function evaluate

ST_DM/AAAI2021-CWatcher/code/eval.py:9–34  ·  view source on GitHub ↗
(reference_city, target_city, Encoder, Classifier, epoch_num)

Source from the content-addressed store, hash-verified

7from tqdm import tqdm
8
9def 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
36if __name__ == '__main__':
37 parser = argparse.ArgumentParser(description="evaluate c-watcher on target city.")

Callers 1

eval.pyFile · 0.70

Calls 9

City_DatasetClass · 0.85
EncoderClass · 0.85
ClassifierClass · 0.85
DataLoaderClass · 0.50
encoderFunction · 0.50
loadMethod · 0.45
evalMethod · 0.45
updateMethod · 0.45
accumulateMethod · 0.45

Tested by

no test coverage detected