def main(_): attrs = conf.__dict__['__flags'] pp(attrs) dataset, img_feature, train_data = get_data(conf.input_json, conf.input_img_h5, conf.input_ques_h5, conf.img_norm) gpu_options = tf.GPUOptions( per_process_gpu_memory_fraction=calc_gpu_fraction(conf.gpu_fraction)) with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)) as sess: model = question_generator.Question_Generator(sess, conf, dataset, img_feature, train_data) if conf.is_train: model.build_model() model.train() else: model.build_generator() model.test(test_image_path=conf.test_image_path, model_path=conf.test_model_path, maxlen=26)
def home(): image_path_array = request.json['image_path_array'] image_paths = [ each_path[1:-1].replace('////', '/') for each_path in image_path_array[1:-1].split(', ') ] questions = [] gpu_options = tf.GPUOptions( per_process_gpu_memory_fraction=calc_gpu_fraction(conf.gpu_fraction)) with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)) as sess: model = question_generator.Question_Generator(sess, conf, dataset, img_feature, train_data) model.build_generator() for image_path in image_paths: question = model.test(test_image_path=image_path, model_path=conf.test_model_path, maxlen=26) questions.append(question) return jsonify({'result': questions}), 200
def main(_): attrs = conf.__dict__['__flags'] pp(attrs) train_data = pickle.load(open('data/prepro.pkl', 'rb')) dataset = pickle.load(open('assets/data_prepro.json', 'rb')) gpu_options = tf.GPUOptions( per_process_gpu_memory_fraction=calc_gpu_fraction(conf.gpu_fraction)) with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)) as sess: model = question_generator.Question_Generator(sess, conf, dataset, train_data) if conf.is_train: model.build_model() model.train() else: model.build_generator() model.test(test_image_path=conf.test_image_path, model_path=conf.test_model_path, maxlen=26)