from keras.models import load_model
from keras import backend as K
from keras_contrib.layers.normalization.instancenormalization import InstanceNormalization
import numpy as np
import model_utils
import data_utils
K.clear_session()

# load the already trained model
test_model=load_model(r"input/out_gpu/time_256ms_ResNet-CBAM256ms_013_0.9430_0.9751.h5",
                      custom_objects={'InstanceNormalization': InstanceNormalization})


# 64ms, 128ms, 256ms
choonse_time_bin="256ms"
data_set_dir=r"/workspace/binary_distinguish_GRB_by_DL-main/Binary_Distinguish_GRB_Datasetv1/data/dataset_256ms/"

# load and pre-process data (train and validate)
(test_x, test_y, test_info)=data_utils.get_test_data(data_set_dir,choonse_time_bin)
# use the model to predict
test_predict_y=test_model.predict(test_x)

predict_class=np.argmax(test_predict_y,axis=1)
real_class=np.argmax(test_y,axis=1)

# output the: accuracy；precision；recall；f1_score
model_utils.printMetrics(real_class, predict_class)