def predict(image_path): size = FLAGS.image_size, FLAGS.image_size img = get_X(image_path, size) ret = model.predict(np.array([img])) ret = np.squeeze(ret) index = np.argmax(ret, axis=0) text = int2text(index, FLAGS.wordset) return text
def predict(image_path): size = FLAGS.image_width, FLAGS.image_height img = get_X(image_path, size) ret = model.predict(np.array([img])) ret = ret.reshape(FLAGS.captcha_size, FLAGS.charset_size) index = np.argmax(ret, axis=1) text = index2text(index, FLAGS.charset) return text
def predict_top_5(image_path): size = FLAGS.image_size, FLAGS.image_size img = get_X(image_path, size) ret = model.predict(np.array([img])) ret = np.squeeze(ret) ret = np.argsort(ret) ret = ret[-5:][::-1] text = [int2text(index, FLAGS.wordset) for index in ret] return text
def predict(img): size = (FLAGS.image_size, FLAGS.image_size) image = get_X(img, size) predict_opts = [graph['predicted_val_top_k'], graph['predicted_index_top_k']] feed_dict = {graph['images']: [image], graph['keep_prob']: 1.0, graph['is_training']: False} predict_val, predict_index = sess.run(predict_opts, feed_dict=feed_dict) predict_index = predict_index.flatten() text = int2text(predict_index[0], FLAGS.wordset) return text
def inference(image): print('inference') from preprocess import get_X temp_image = get_X(image) with tf.Session() as sess: logger.info('========start inference============') # images = tf.placeholder(dtype=tf.float32, shape=[None, 64, 64, 1]) # Pass a shadow label 0. This label will not affect the computation graph. graph = build_graph(top_k=3) saver = tf.train.Saver() ckpt = tf.train.latest_checkpoint(FLAGS.checkpoint_dir) if ckpt: saver.restore(sess, ckpt) predict_val, predict_index = sess.run( [graph['predicted_val_top_k'], graph['predicted_index_top_k']], feed_dict={ graph['images']: temp_image, graph['keep_prob']: 1.0, graph['is_training']: False }) return predict_val, predict_index
import pandas as pd import preprocess import tensorflow as tf from sklearn.preprocessing import MultiLabelBinarizer from sklearn.utils import shuffle data = pd.read_csv("myFP_217_D2.csv", header=None) D2 = preprocess.get_data(data) X = preprocess.get_X(D2) X = preprocess.comb(X) # y = pd.DataFrame(preprocess.get_target(D2)) value = preprocess.get_target(D2) value = MultiLabelBinarizer().fit_transform(value) y = pd.DataFrame(value) X, y = shuffle(X, y, random_state=0) X_train, X_test = X[:int((0.8 * len(X)))], X[int((0.8 * len(X))):] y_train, y_test = y[:int((0.8 * len(X)))], y[int((0.8 * len(X))):] def rnn1(): n_nodes_hl1 = 1024 n_nodes_hl2 = 512 n_nodes_hl3 = 256 n_classes = 7 batch_size = 100 x = tf.placeholder(tf.float32, [None, 2048], name="features")