import numpy as np import time import matplotlib.pyplot as plt from data_loader import loaddata from model import MLP import argparse import logging logging.basicConfig(level=logging.DEBUG) #init config d0 = 784 #datadimension d1 = h = 1000 #number of hidden units d2 = C = 10 #number of classes #init model model = MLP(d0, d1, d2) time.sleep(1) #load model parser = argparse.ArgumentParser() parser.add_argument('--input_dir') parser.add_argument('--check_point', default = 'model') args = parser.parse_args() model.load_checkpoint(args.check_point) #load img result = model.test(args.input_dir) logging.info('Result is {}'.format(result))
for k, r in enumerate(rlist): salience_map[j][r] = Y[k] _, _, weights = rf_sal.get_weights(im_data.feature93s[j]) rf_sal_weight += np.mean(weights, axis=0)[:, 1] rf_sal_weight /= len(im_data.rlists) ground_truth = cv2.imread(seg_paths[i])[:, :, 0] ground_truth[ground_truth == 255] = 1 x = salience_map.reshape([-1, height * width]).T salience_maps.append(x) ground_truths.append(ground_truth.reshape(-1)) result = mlp.predict(x).reshape([height, width, 1]) result[result > 0.5] = 255 result[result <= 0.5] = 0 cv2.imwrite("data/result/{}.png".format(its[i]), result.astype(np.uint8)) print("finish w {}".format(i)) X_test = np.array(salience_maps) X_test = np.concatenate(X_test, axis=0) Y_test = np.array(ground_truths) Y_test = np.concatenate(Y_test, axis=0) mlp.test(X_test, Y_test) df = pd.DataFrame(rf_sal_weight / len(img_datas)) df.to_csv("data/csv/rf_sal_weight.csv")