from io import BytesIO from datetime import datetime from flask import Flask, request, render_template from random import random, choice from lib import data_util from lib.config import params_setup from lib.googlenet import GoogLeNet app = Flask(__name__) # model # scope_name, label_size = '17flowers', 17 # scope_name, label_size = '17portraits', 9 args = params_setup() gnet = GoogLeNet(args=args) #--------------------------- # Server #--------------------------- @app.route('/', methods=['GET']) def guess(): url = request.args.get('url', '') if url: X = url2sample(url) probs = gnet.predict([X])[0] cnt = int(sum([math.exp(i + 4) * probs[i] for i in range(len(probs))])) probs = [(i, round(100 * p, 1)) for i, p in enumerate(probs)] else: cnt, probs = None, None
from __future__ import division, print_function, absolute_import from lib import data_util from lib.config import params_setup from lib.googlenet import GoogLeNet from datetime import datetime import pickle, gzip import numpy as np import tflearn.datasets.oxflower17 as oxflower17 #------------------------------- # Training #------------------------------- # scope_name, label_size = '17flowers', 17 # scope_name, label_size = '17portraits', 9 args = params_setup() gnet = GoogLeNet(args=args) #img_size=227, label_size=label_size, gpu_memory_fraction=0.4, scope_name=scope_name) pkl_files = gnet.get_data(dirname=args.model_name, down_sampling=args.down_sampling) epoch = 0 while True: for f in pkl_files: X, Y = pickle.load(gzip.open(f, 'rb')) gnet.fit(X, Y, n_epoch=10) print('[pkl_files] done with %s @ %s' % (f, datetime.now())) epoch += 1 # print("[Finish] all pkl_files been trained %i times." % epoch)
from lib.config import params_setup from lib.googlenet import GoogLeNet from datetime import datetime import tensorflow as tf import tflearn import pickle, gzip import numpy as np import tflearn.datasets.oxflower17 as oxflower17 # ------------------------------- # Training # ------------------------------- args = params_setup() gnet = GoogLeNet(args=args) # img_size=227, label_size=label_size, gpu_memory_fraction=0.4, scope_name=scope_name) pkl_files = gnet.get_data(dirname=args.model_name, down_sampling=args.down_sampling) epoch = 0 while True: for f in pkl_files: X, Y = pickle.load(gzip.open(f, 'rb')) with tf.device('/device:GPU:0'): gnet.fit(X, Y, n_epoch=10) print('[pkl_files] done with %s @ %s' % (f, datetime.now())) epoch += 1 print("[Finish] all pkl_files been trained %i times." % epoch)
import pickle, gzip import numpy as np import tflearn.datasets.oxflower17 as oxflower17 # import AI Vision train service module from dnn_train import train_service #------------------------------- # Training #------------------------------- # init AI Vision train service train_service = train_service.TrainService() args = params_setup() gnet = GoogLeNet(args, train_service) # go to pre-processing stage train_service.sendStatusMessagePreproccess() # go to training stage train_service.sendStatusMessageTrain() print(pkl_files) for f in pkl_files: X, Y = pickle.load(gzip.open(f, 'rb')) gnet.fit(X, Y, n_epoch=100) gnet.save() print('[pkl_files] done with %s @ %s' % (f, datetime.now())) # go to complete stage train_service.sendStatusMessageComplete()
import numpy as np from PIL import Image from scipy import misc from io import BytesIO from datetime import datetime from flask import Flask, request, render_template from random import random, choice from lib import data_util from lib.config import params_setup from lib.googlenet import GoogLeNet # model args = params_setup() gnet = GoogLeNet(args=args) directory_names = list(set(glob.glob(os.path.join("images","tiny-imagenet-200","jpg", "*"))\ ).difference(set(glob.glob(os.path.join("images","tiny-imagenet-200","jgp","*.*",))))) total_count = 0. correct_count = 0. # len(directory_names) for i in range(len(directory_names)): imgs_in_folder = glob.glob( os.path.join(directory_names[i], "images", "*.JPEG")) for j in range(400, len(imgs_in_folder)): cur_img = imgs_in_folder[j] # img = imread(cur_img) # img = load_image(s) # img = Image.open(cur_img) # # img = resize_image(img, 227, 227)