def scao_model_iv(AI_saved_dir, arti_flux_678, arti_label_678): #----------------------------------- # Load AI print('Loading AI...') width_of_data = 1 img_maj = 3 image_shape = (width_of_data, img_maj) kernal_shape = (width_of_data, 2) num_kernal_1 = 32 num_kernal_2 = 64 num_conn_neural = 100 num_label = 3 #----------------------------------- # Construct an AI tf.reset_default_graph() x = tf.placeholder(tf.float32, [None, width_of_data * img_maj], name='x') y_true = tf.placeholder(tf.float32, [None, 3], name='y_true') y_true_cls = tf.argmax(y_true, axis=1) x_image = tf.reshape(x, [-1, image_shape[0], image_shape[1], 1]) # First layer( First kernal) W_conv1 = weight_variable( [kernal_shape[0], kernal_shape[1], 1, num_kernal_1]) b_conv1 = bias_variable([num_kernal_1]) h_conv1 = tf.nn.selu( tf.nn.conv2d(x_image, W_conv1, [1, 1, 1, 1], 'SAME') + b_conv1) # Second layer( Second kernal) W_conv2 = weight_variable( [kernal_shape[0], kernal_shape[1], num_kernal_1, num_kernal_2]) b_conv2 = bias_variable([num_kernal_2]) h_conv2 = tf.nn.selu( tf.nn.conv2d(h_conv1, W_conv2, [1, 1, 1, 1], 'SAME') + b_conv2) # Third layer ( Fully connected) W_fc1 = weight_variable( [image_shape[0] * image_shape[1] * num_kernal_2, num_conn_neural]) b_fc1 = bias_variable([num_conn_neural]) h_conv2_flat = tf.reshape( h_conv2, [-1, image_shape[0] * image_shape[1] * num_kernal_2]) h_fc1 = tf.nn.selu(tf.matmul(h_conv2_flat, W_fc1) + b_fc1) # Output layer W_fc2 = weight_variable([num_conn_neural, num_label]) b_fc2 = bias_variable([num_label]) layer_last = tf.matmul(h_fc1, W_fc2) + b_fc2 y_pred = tf.nn.softmax(layer_last) y_pred_cls = tf.argmax(y_pred, axis=1) correct_prediction = tf.equal(y_pred_cls, y_true_cls) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) # Saver saver = tf.train.Saver() print("AI:{0}".format(AI_saved_dir)) if not os.path.exists(AI_saved_dir): print("No AI can be restore, please check folder ./checkpoints") exit(1) save_path = os.path.join(AI_saved_dir, 'best_validation') session = tf.Session() # Restore previous weight saver.restore(sess=session, save_path=save_path) #----------------------------------- # Make a prediction def predict_label(images, labels): # Number of images. num_images = len(images) # initialize label_pred = np.zeros(num_images * 3).reshape((num_images, 3)) feed_dict = {x: images[:], y_true: labels[:]} # process label_pred = session.run(y_pred, feed_dict=feed_dict) return label_pred label_pred_678 = predict_label(arti_flux_678, arti_label_678) #----------------------------------- # Close session session.close() return label_pred_678
img_maj = 3 image_shape = (width_of_data, img_maj) kernal_shape = (width_of_data, 2) num_kernal_1 = 32 num_kernal_2 = 64 num_conn_neural = 100 num_label = 3 #----------------------------------- # Construct an AI tf.reset_default_graph() x = tf.placeholder(tf.float32, [None, width_of_data * img_maj], name='x') y_true = tf.placeholder(tf.float32, [None, 3], name='y_true') y_true_cls = tf.argmax(y_true, axis=1) x_image = tf.reshape(x, [-1, image_shape[0], image_shape[1], 1]) # First layer( First kernal) W_conv1 = weight_variable( [kernal_shape[0], kernal_shape[1], 1, num_kernal_1]) b_conv1 = bias_variable([num_kernal_1]) h_conv1 = tf.nn.selu( tf.nn.conv2d(x_image, W_conv1, [1, 1, 1, 1], 'SAME') + b_conv1) # Second layer( Second kernal) W_conv2 = weight_variable( [kernal_shape[0], kernal_shape[1], num_kernal_1, num_kernal_2]) b_conv2 = bias_variable([num_kernal_2]) h_conv2 = tf.nn.selu( tf.nn.conv2d(h_conv1, W_conv2, [1, 1, 1, 1], 'SAME') + b_conv2) # Third layer ( Fully connected) W_fc1 = weight_variable( [image_shape[0] * image_shape[1] * num_kernal_2, num_conn_neural]) b_fc1 = bias_variable([num_conn_neural]) h_conv2_flat = tf.reshape( h_conv2, [-1, image_shape[0] * image_shape[1] * num_kernal_2])