def main() -> None: if len(sys.argv) <= 1: print( 'Usage: python main.py [1 or 2 for 2b part 1 and 2 respectively]') exit(-1) sim_to_run = sys.argv[1] factors = [ Factor(['Trav'], [], [0.05, 0.95]), Factor(['Fraud'], ['Trav'], [0.01, 0.99, 0.004, 0.996]), Factor(['OC'], [], [0.7, 0.3]), Factor(['CRP'], ['OC'], [0.1, 0.9, 0.001, 0.999]), Factor(['FP'], ['Trav', 'Fraud'], [0.9, 0.1, 0.9, 0.1, 0.1, 0.9, 0.01, 0.99]), Factor(['IP'], ['OC', 'Fraud'], [0.02, 0.98, 0.01, 0.99, 0.011, 0.989, 0.001, 0.999]) ] if sim_to_run == '1': inference(factors, ['Fraud'], ['Trav', 'FP', 'IP', 'OC', 'CRP'], []) else: inference(factors, ['Fraud'], ['Trav', 'OC'], [('FP', Sign.POSITIVE), ('IP', Sign.NEGATIVE), ('CRP', Sign.POSITIVE)])
def main(): root = tkinter.Tk() root.geometry('300x400') frame = tkinter.Frame(root, width=256, height=256) frame.pack_propagate(0) frame.pack(side='top') canvas1 = MyCanvas(frame) infer = inference() def inference_click(): img = canvas1.image1 result = infer.predict(img) result = int(result) canvas1.canvas.delete("all") canvas1.image1 = Image.new("RGB", (256, 256), "black") canvas1.draw = ImageDraw.Draw(canvas1.image1) label2["text"] = str(result) botton_Inference = tkinter.Button(root, text="Inference", width=7, height=1, command=inference_click) botton_Inference.pack() label1 = tkinter.Label(root, justify="center", text="Inference result is") label1.pack() label2 = tkinter.Label(root, justify="center") label2["font"] = ("Arial, 48") label2.pack() root.mainloop()
def main(): root = tkinter.Tk() root.geometry('300x400') frame = tkinter.Frame(root, width=256, height=256) frame.pack_propagate(0) frame.pack(side='top') canvas1 = MyCanvas(frame) infer = inference() def inference_click(): img = canvas1.image1 result = infer.predict(img) result = int(result) canvas1.canvas.delete("all") canvas1.image1 = Image.new("RGB", (256, 256), "black") canvas1.draw = ImageDraw.Draw(canvas1.image1) label2["text"] = str(result) botton_Inference = tkinter.Button(root, text="Inference", width=7, height=1, command=inference_click ) botton_Inference.pack() label1 = tkinter.Label(root, justify="center", text="Inference result is") label1.pack() label2 = tkinter.Label(root, justify="center") label2["font"] = ("Arial, 48") label2.pack() root.mainloop()
def inference_click(): img = canvas1.image1 result = inference(img) result = int(result) canvas1.canvas.delete("all") canvas1.image1 = Image.new("RGB", (256, 256), "black") canvas1.draw = ImageDraw.Draw(canvas1.image1) label2["text"] = str(result)
def main(): # ................................产生随机数................................. ram_x_t_data1 = np.random.rand(50, 10) ram_x_t_data2 = np.random.rand(50, 256) ram_y_t_data = np.ones([500, 1]) path = './vgg_output/Data1_fc2_D_no_D1.txt' path1 = './vgg_output/Data1_fc1_D_no_D1.txt' input = np.loadtxt(path) input1 = np.loadtxt(path1) Inter = inference() result, accuracy = Inter.predict(input, input1, ram_y_t_data) print('The result of predicting is \n', result) print('accuracy is ', accuracy)
#!/usr/bin/python3.6 """ @Author: xiaxianyi<*****@*****.**> @Time: 2021/4/5 9:11 @File: test.py Description: """ import tensorflow as tf from Inference import inference import tensorflow_core.examples.tutorials.mnist.input_data as input_data if __name__ == '__main__': mnist = input_data.read_data_sets("MNIST_data/", one_hot=False) infer = inference() test_data = mnist.test num_examples = test_data._num_examples count = 0 for i in range(num_examples): batch = mnist.train.next_batch(1) pred = infer.predict(batch[0]) label = batch[1] if pred[0] == label[0]: count += 1 print("test data accuracy: ", count / 10000)
with open(Name_list, "r") as f: lines = f.read().splitlines() lines_shuffled = np.random.permutation(lines) Sample_size = 500 lines_sampled = lines_shuffled[0:Sample_size] iou_vec = np.zeros((21, 3, 3)) for i, theta1 in enumerate(np.linspace(1, 121, 3)): for j, theta2 in enumerate(np.linspace(1, 21, 3)): int_vec = np.zeros((21, Sample_size)) union_vec = np.zeros((21, Sample_size)) theta = np.array([theta1, theta2]) for ptr, line in enumerate(lines_sampled): Q = inference(theta, line, Image_dir, Unary_dir, Prediction_dir, False) img_truth_name = os.path.join(Ground_truth_dir, line) + '.png' img_truth = imread(img_truth_name) truth_data = utils.convert_from_color_segmentation(img_truth) for class_idx in range(0, 21): int_i, uni_i = eval.int_uni_cls(truth_data, Q, class_idx) int_vec[class_idx, ptr] = int_i union_vec[class_idx, ptr] = uni_i iou_vec[:, i, j] = [ np.sum(int_vec[i]) / np.sum(union_vec[i]) for i in range(21) ] scipy.io.savemat( os.path.join(output_path, "grid_search_" + str(i * 3 + j)), {"grid_search": iou_vec[:, i, j]}) scipy.io.savemat(os.path.join(output_path, "grid_search"), {"grid_search": iou_vec})