Commit c873c851 by BoxuanXu

add progress

1 parent 55a6e272
...@@ -16,6 +16,7 @@ from flask import Flask,request ...@@ -16,6 +16,7 @@ from flask import Flask,request
from jenkinsapi.jenkins import Jenkins from jenkinsapi.jenkins import Jenkins
import GProgress as GP
import Queue import Queue
__website__ = "www.seetatech.com" __website__ = "www.seetatech.com"
...@@ -34,6 +35,13 @@ download_path="." ...@@ -34,6 +35,13 @@ download_path="."
#be userd to jenkins #be userd to jenkins
host = 'http://192.168.1.242:8080/' host = 'http://192.168.1.242:8080/'
modelid = ""
output_layer = ""
pool_id = ""
err_msg = ""
post_url = "http://192.168l.1.170:1234/API"
#post_url = "http://192.168.1.244:5000/result"
#init post info queue #init post info queue
Info_Queue = Queue.Queue() Info_Queue = Queue.Queue()
...@@ -102,6 +110,8 @@ def get_path_from_db(modelid,seetanet_model): ...@@ -102,6 +110,8 @@ def get_path_from_db(modelid,seetanet_model):
else: else:
return None,None return None,None
GP.set_progress_var(20)
GP.Post_return()
#Driver converter model by params and model graph #Driver converter model by params and model graph
Run_Converter(params_name,graph_name,seetanet_model) Run_Converter(params_name,graph_name,seetanet_model)
...@@ -127,13 +137,21 @@ def get_info_from_queue(arg): ...@@ -127,13 +137,21 @@ def get_info_from_queue(arg):
logging.info("Begin Convert Info is : modelid = %s, output_layer = %s ,Post_Host = %s" % (Info["modelid"],Info["output_layer"],Info["post_url"])) logging.info("Begin Convert Info is : modelid = %s, output_layer = %s ,Post_Host = %s" % (Info["modelid"],Info["output_layer"],Info["post_url"]))
return_flag = "FALSE" return_flag = "TRUE"
post_url = "http://127.0.0.1" modelid = Info["modelid"]
output_layer = Info["output_layer"]
pool_id = Info["pool_id"]
GP.set_pool_id_var(pool_id)
GP.set_err_msg_var("")
err_msg = ""
GP.set_post_type_var(return_flag)
try: try:
modelid = Info["modelid"] #post return progress
output_layer = Info["output_layer"] GP.set_progress_var(10)
post_url = Info["post_url"] GP.Post_return()
seetanet_model = "model_" + str(modelid) + ".data" seetanet_model = "model_" + str(modelid) + ".data"
...@@ -142,12 +160,14 @@ def get_info_from_queue(arg): ...@@ -142,12 +160,14 @@ def get_info_from_queue(arg):
if params_name is None or graph_name is None: if params_name is None or graph_name is None:
logging.info("get wrong params file") logging.info("get wrong params file")
err_msg = "get wrong params file"
return_flag = "FALSE" return_flag = "FALSE"
else: else:
stmodel_fid = upload_filetoFastDFS(params_name, graph_name,seetanet_model) stmodel_fid = upload_filetoFastDFS(params_name, graph_name,seetanet_model)
if stmodel_fid is None: if stmodel_fid is None:
logging.info("upload filed") logging.info("upload filed")
err_msg = "upload filed"
return_flag = "FALSE" return_flag = "FALSE"
else: else:
...@@ -158,6 +178,7 @@ def get_info_from_queue(arg): ...@@ -158,6 +178,7 @@ def get_info_from_queue(arg):
subprocess.check_call(cmd_str,shell=True) subprocess.check_call(cmd_str,shell=True)
except subprocess.CalledProcessError as err: except subprocess.CalledProcessError as err:
logging.info("shell command error!") logging.info("shell command error!")
err_msg = "shell command error!"
return_flag = "FALSE" return_flag = "FALSE"
...@@ -165,6 +186,8 @@ def get_info_from_queue(arg): ...@@ -165,6 +186,8 @@ def get_info_from_queue(arg):
logging.info("Begin Run JenkIn!") logging.info("Begin Run JenkIn!")
GP.set_progress_var(90)
GP.Post_return()
J = Jenkins(host, username='shenyizhong', password='shenyizhong') J = Jenkins(host, username='shenyizhong', password='shenyizhong')
job = J['SeetaNetLite-pro'] job = J['SeetaNetLite-pro']
...@@ -179,10 +202,24 @@ def get_info_from_queue(arg): ...@@ -179,10 +202,24 @@ def get_info_from_queue(arg):
if b.get_status() == "SUCCESS": if b.get_status() == "SUCCESS":
return_flag = "SUCCESS" return_flag = "SUCCESS"
else: else:
err_msg = "JenkIn Wrong False"
return_flag = "FALSE" return_flag = "FALSE"
except Exception, e:
#GP.set_err_msg_var(repr(e))
err_msg = repr(e)
return_flag = "FALSE"
finally: finally:
post_return = { "modelid": modelid, "return_flag" : return_flag } GP.set_post_type_var(return_flag)
requests.post(post_url, data=post_return) GP.set_err_msg_var(err_msg)
if return_flag == "SUCCESS":
GP.set_progress_var(100)
#post_return = { "posttype": return_flag, "progress" : 100, "pool_id": pool_id, "err_msg":err_msg }
else:
GP.set_progress_var(0)
#post_return = { "posttype": return_flag, "progress" : 0, "pool_id": pool_id, "err_msg":err_msg }
GP.Post_return()
t = threading.Thread(target=get_info_from_queue,args=(1,)) t = threading.Thread(target=get_info_from_queue,args=(1,))
...@@ -190,14 +227,18 @@ t = threading.Thread(target=get_info_from_queue,args=(1,)) ...@@ -190,14 +227,18 @@ t = threading.Thread(target=get_info_from_queue,args=(1,))
@app.route('/convert',methods=['POST']) @app.route('/convert',methods=['POST'])
def Dirver_Convert(): def Dirver_Convert():
#get parameter modelid from post stream #get parameter modelid from post stream
return_flag = "Packing..." return_flag = "TRUE"
try: try:
modelid=request.form['modelid'] modelid=request.form['modelid']
output_layer=request.form['output_layer'] output_layer=request.form['output_layer']
post_url=request.form['post_url'] pool_id=request.form['pool_id']
if modelid == '' or modelid == None or output_layer == '' or output_layer == None or pool_id == '' or output_layer == None:
logging.info("New Post Connect: get wrong parameter!")
return_flag = "FALSE"
else:
logging.info("New Post Connect: modelid : %s , post_url : %s, Queue size : %d" % (modelid,post_url,(Info_Queue.qsize() + 1))) logging.info("New Post Connect: modelid : %s , post_url : %s, Queue size : %d" % (modelid,post_url,(Info_Queue.qsize() + 1)))
Post_Info = { "modelid": modelid, "output_layer" : output_layer,"post_url" : post_url} Post_Info = { "modelid": modelid, "output_layer" : output_layer,"pool_id" : pool_id}
Info_Queue.put(Post_Info) Info_Queue.put(Post_Info)
if t.is_alive(): if t.is_alive():
......
#!/usr/bin/env python
#_*_ coding: UTF-8 _*_
__website__ = "www.seetatech.com"
__author__ = "seetatech"
__editor__ = "xuboxuan"
__Date__ = "20170812"
import requests
#post_url = "http://192.168l.1.170:1234/API"
post_url = "http://192.168.1.244:5000/result"
class GProgress_Var:
posttype = None;
progress = None;
pool_id = None;
err_msg = None;
def set_post_type_var(posttype):
GProgress_Var.posttype = posttype
def set_progress_var(progress):
GProgress_Var.progress = progress
def set_pool_id_var(pool_id):
GProgress_Var.pool_id = pool_id
def set_err_msg_var(err_msg):
GProgress_Var.err_msg = err_msg
def Post_return():
post_return = { "posttype": GProgress_Var.posttype, "progress" : GProgress_Var.progress, "pool_id": GProgress_Var.pool_id, "err_msg":GProgress_Var.err_msg }
requests.post(post_url, data=post_return)
...@@ -5,6 +5,7 @@ from mxnet_graph import load_graph ...@@ -5,6 +5,7 @@ from mxnet_graph import load_graph
import numpy as np import numpy as np
import logging import logging
import config as cfg import config as cfg
import GProgress as GP
logging.basicConfig( logging.basicConfig(
level=logging.INFO, level=logging.INFO,
format="[%(asctime)s] %(name)s:%(levelname)s: %(message)s" format="[%(asctime)s] %(name)s:%(levelname)s: %(message)s"
...@@ -345,6 +346,7 @@ class Converter(object): ...@@ -345,6 +346,7 @@ class Converter(object):
self.write_layer_names(fo, True) self.write_layer_names(fo, True)
self.write_layer_names(fo) self.write_layer_names(fo)
try: try:
flag = 1;
for i in range(self.__graph.idx_count): for i in range(self.__graph.idx_count):
if i == 1: continue if i == 1: continue
layer = self.__graph.get_layer(self.__graph.get_name(i)) layer = self.__graph.get_layer(self.__graph.get_name(i))
...@@ -370,12 +372,20 @@ class Converter(object): ...@@ -370,12 +372,20 @@ class Converter(object):
length = np.array(len(ss), np.int64) length = np.array(len(ss), np.int64)
fo.write(length.tobytes()) fo.write(length.tobytes())
fo.write(ss) fo.write(ss)
#post return progress
if(i > (flag * (self.__graph.idx_count / 6))):
GP.set_progress_var(flag * 10 + 20)
GP.Post_return()
flag = flag + 1
# 加最后一个标记层 # 加最后一个标记层
wapper = self.__last_layer() wapper = self.__last_layer()
ss = wapper.SerializeToString() ss = wapper.SerializeToString()
length = np.array(len(ss), np.int64) length = np.array(len(ss), np.int64)
fo.write(length.tobytes()) fo.write(length.tobytes())
fo.write(ss) fo.write(ss)
except Exception, e:
GP.set_err_msg_var(repr(e))
finally: finally:
fo.close() fo.close()
...@@ -411,9 +421,6 @@ def Run_Converter(model_param,model_json,seetanet_model): ...@@ -411,9 +421,6 @@ def Run_Converter(model_param,model_json,seetanet_model):
graph = load_graph(model_json) graph = load_graph(model_json)
converter = Converter(graph, arg_params, aux_params) converter = Converter(graph, arg_params, aux_params)
logging.info('start to convert model parameters') logging.info('start to convert model parameters')
print(model_param)
print(model_json)
print(seetanet_model)
converter.convert(seetanet_model) converter.convert(seetanet_model)
logging.info('convert success!!!') logging.info('convert success!!!')
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!