Commit c873c851 by BoxuanXu

add progress

1 parent 55a6e272
......@@ -16,6 +16,7 @@ from flask import Flask,request
from jenkinsapi.jenkins import Jenkins
import GProgress as GP
import Queue
__website__ = "www.seetatech.com"
......@@ -34,6 +35,13 @@ download_path="."
#be userd to jenkins
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
Info_Queue = Queue.Queue()
......@@ -102,6 +110,8 @@ def get_path_from_db(modelid,seetanet_model):
else:
return None,None
GP.set_progress_var(20)
GP.Post_return()
#Driver converter model by params and model graph
Run_Converter(params_name,graph_name,seetanet_model)
......@@ -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"]))
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:
modelid = Info["modelid"]
output_layer = Info["output_layer"]
post_url = Info["post_url"]
#post return progress
GP.set_progress_var(10)
GP.Post_return()
seetanet_model = "model_" + str(modelid) + ".data"
......@@ -142,12 +160,14 @@ def get_info_from_queue(arg):
if params_name is None or graph_name is None:
logging.info("get wrong params file")
err_msg = "get wrong params file"
return_flag = "FALSE"
else:
stmodel_fid = upload_filetoFastDFS(params_name, graph_name,seetanet_model)
if stmodel_fid is None:
logging.info("upload filed")
err_msg = "upload filed"
return_flag = "FALSE"
else:
......@@ -158,6 +178,7 @@ def get_info_from_queue(arg):
subprocess.check_call(cmd_str,shell=True)
except subprocess.CalledProcessError as err:
logging.info("shell command error!")
err_msg = "shell command error!"
return_flag = "FALSE"
......@@ -165,6 +186,8 @@ def get_info_from_queue(arg):
logging.info("Begin Run JenkIn!")
GP.set_progress_var(90)
GP.Post_return()
J = Jenkins(host, username='shenyizhong', password='shenyizhong')
job = J['SeetaNetLite-pro']
......@@ -179,10 +202,24 @@ def get_info_from_queue(arg):
if b.get_status() == "SUCCESS":
return_flag = "SUCCESS"
else:
err_msg = "JenkIn Wrong False"
return_flag = "FALSE"
except Exception, e:
#GP.set_err_msg_var(repr(e))
err_msg = repr(e)
return_flag = "FALSE"
finally:
post_return = { "modelid": modelid, "return_flag" : return_flag }
requests.post(post_url, data=post_return)
GP.set_post_type_var(return_flag)
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,))
......@@ -190,14 +227,18 @@ t = threading.Thread(target=get_info_from_queue,args=(1,))
@app.route('/convert',methods=['POST'])
def Dirver_Convert():
#get parameter modelid from post stream
return_flag = "Packing..."
return_flag = "TRUE"
try:
modelid=request.form['modelid']
output_layer=request.form['output_layer']
post_url=request.form['post_url']
modelid=request.form['modelid']
output_layer=request.form['output_layer']
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)))
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)
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
import numpy as np
import logging
import config as cfg
import GProgress as GP
logging.basicConfig(
level=logging.INFO,
format="[%(asctime)s] %(name)s:%(levelname)s: %(message)s"
......@@ -345,6 +346,7 @@ class Converter(object):
self.write_layer_names(fo, True)
self.write_layer_names(fo)
try:
flag = 1;
for i in range(self.__graph.idx_count):
if i == 1: continue
layer = self.__graph.get_layer(self.__graph.get_name(i))
......@@ -370,12 +372,20 @@ class Converter(object):
length = np.array(len(ss), np.int64)
fo.write(length.tobytes())
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()
ss = wapper.SerializeToString()
length = np.array(len(ss), np.int64)
fo.write(length.tobytes())
fo.write(ss)
except Exception, e:
GP.set_err_msg_var(repr(e))
finally:
fo.close()
......@@ -411,9 +421,6 @@ def Run_Converter(model_param,model_json,seetanet_model):
graph = load_graph(model_json)
converter = Converter(graph, arg_params, aux_params)
logging.info('start to convert model parameters')
print(model_param)
print(model_json)
print(seetanet_model)
converter.convert(seetanet_model)
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!