Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
BoxuanXu
/
FlaskDriverMXNet2SeetaNet
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 7bac27b1
authored
Aug 08, 2017
by
BoxuanXu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add multy thread
1 parent
591a5745
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
43 deletions
Drive_Converter.py
Drive_Converter.py
View file @
7bac27b
...
@@ -7,11 +7,17 @@ import subprocess
...
@@ -7,11 +7,17 @@ import subprocess
from
libpywrap
import
*
from
libpywrap
import
*
import
requests
import
threading
from
converter
import
Run_Converter
from
converter
import
Run_Converter
from
flask
import
Flask
,
request
from
flask
import
Flask
,
request
from
jenkinsapi.jenkins
import
Jenkins
from
jenkinsapi.jenkins
import
Jenkins
import
Queue
__website__
=
"www.seetatech.com"
__website__
=
"www.seetatech.com"
__author__
=
"seetatech"
__author__
=
"seetatech"
__editor__
=
"xuboxuan"
__editor__
=
"xuboxuan"
...
@@ -28,6 +34,9 @@ download_path="."
...
@@ -28,6 +34,9 @@ download_path="."
#be userd to jenkins
#be userd to jenkins
host
=
'http://192.168.1.242:8080/'
host
=
'http://192.168.1.242:8080/'
#init post info queue
Info_Queue
=
Queue
.
Queue
()
#initlization the logging
#initlization the logging
logging
.
basicConfig
(
logging
.
basicConfig
(
level
=
logging
.
INFO
,
level
=
logging
.
INFO
,
...
@@ -92,7 +101,8 @@ def get_path_from_db(modelid,seetanet_model):
...
@@ -92,7 +101,8 @@ def get_path_from_db(modelid,seetanet_model):
#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)
Run_Converter
(
"model-0015.params"
,
"model-symbol.json"
,
seetanet_model
)
return
params_name
,
graph_name
return
params_name
,
graph_name
...
@@ -107,62 +117,93 @@ def upload_filetoFastDFS(params_name, graph_name,seetanet_model):
...
@@ -107,62 +117,93 @@ def upload_filetoFastDFS(params_name, graph_name,seetanet_model):
return
None
return
None
return
stmodel_fid
return
stmodel_fid
def
get_info_from_queue
(
arg
):
#get parameters and driver the transition function
while
1
:
@app.route
(
'/'
,
methods
=
[
'POST'
])
if
not
Info_Queue
.
empty
():
def
Dirver_Convert
():
Info
=
Info_Queue
.
get
()
#get parameter modelid from post stream
modelid
=
request
.
form
[
'modelid'
]
output_layer
=
request
.
form
[
'output_layer'
]
logging
.
info
(
"We get modelid :
%
s from post stream,Start conversion:"
%
modelid
)
try
:
logging
.
info
(
"Begin Convert Info is : modelid =
%
s, output_layer =
%
s ,Post_Host =
%
s"
%
(
Info
[
"modelid"
],
Info
[
"output_layer"
],
Info
[
"post_url"
]))
seetanet_model
=
"model_"
+
str
(
modelid
)
+
".data"
try
:
modelid
=
Info
[
"modelid"
]
output_layer
=
Info
[
"output_layer"
]
Post_Host
=
Info
[
"post_url"
]
seetanet_model
=
"model_"
+
str
(
modelid
)
+
".data"
params_name
,
graph_name
=
get_path_from_db
(
modelid
,
seetanet_model
)
params_name
,
graph_name
=
get_path_from_db
(
modelid
,
seetanet_model
)
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"
)
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"
)
return
"false"
return_flag
=
"false"
else
:
else
:
#remove params file and graph file
#remove params file and graph file
try
:
try
:
cmd_str
=
"rm -rf "
+
params_name
+
" "
+
graph_name
+
" "
+
seetanet_model
cmd_str
=
"rm -rf "
+
params_name
+
" "
+
graph_name
+
" "
+
seetanet_model
print
(
cmd_str
)
print
(
cmd_str
)
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!"
)
return
"false"
return_flag
=
"false"
logging
.
info
(
"convert successfully!"
)
logging
.
info
(
"convert successfully!"
)
logging
.
info
(
"Begin Run JenkIn!"
)
logging
.
info
(
"Begin Run JenkIn!"
)
J
=
Jenkins
(
host
,
username
=
'shenyizhong'
,
password
=
'shenyizhong'
)
J
=
Jenkins
(
host
,
username
=
'shenyizhong'
,
password
=
'shenyizhong'
)
job
=
J
[
'SeetaNetLite-pro'
]
job
=
J
[
'SeetaNetLite-pro'
]
params
=
"{
\'
MODEL_ID
\'
:
\'
"
+
modelid
+
"
\'
,
\'
OUTPUT_LAYER
\'
:
\'
"
+
output_layer
+
"
\'
,
\'
STMODEL_FID
\'
:
\'
"
+
stmodel_fid
+
"
\'
}"
params
=
"{
\'
MODEL_ID
\'
:
\'
"
+
modelid
+
"
\'
,
\'
OUTPUT_LAYER
\'
:
\'
"
+
output_layer
+
"
\'
,
\'
STMODEL_FID
\'
:
\'
"
+
stmodel_fid
+
"
\'
}"
#convert string to dict
#convert string to dict
params
=
eval
(
params
)
params
=
eval
(
params
)
job
.
invoke
(
block
=
True
,
build_params
=
params
)
job
.
invoke
(
block
=
True
,
build_params
=
params
)
return
"true"
return_flag
=
"true"
finally
:
#curl_atlas_exe.close()
#curl_atlas.close()
#db_atlas.close()
logging
(
'return
%
s'
,
return_flag
)
post_return
=
{
"modelid"
:
modelid
,
"return_flag"
:
return_flag
}
requests
.
post
(
post_url
,
data
=
post_return
)
#get parameters and driver the transition function
@app.route
(
'/convert'
,
methods
=
[
'POST'
])
def
Dirver_Convert
():
#get parameter modelid from post stream
return_flag
=
"queue"
print
(
"haha"
)
try
:
modelid
=
request
.
form
[
'modelid'
]
output_layer
=
request
.
form
[
'output_layer'
]
post_url
=
request
.
form
[
'post_url'
]
logging
.
info
(
"New Post Connect: modelid :
%
s , post_url :
%
s, Queue size :
%
d"
%
(
modelid
,
post_url
,
Info_Queue
.
qsize
()))
Post_Info
=
{
"modelid"
:
modelid
,
"output_layer"
:
output_layer
,
"post_url"
:
post_url
}
Info_Queue
.
put
(
Post_Info
)
finally
:
finally
:
curl_atlas_exe
.
close
()
return
return_flag
curl_atlas
.
close
()
db_atlas
.
close
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
app
.
run
(
host
=
'0.0.0.0'
)
try
:
t
=
threading
.
Thread
(
target
=
get_info_from_queue
,
args
=
(
1
,))
t
.
start
();
app
.
run
(
host
=
'0.0.0.0'
)
finally
:
curl_atlas_exe
.
close
()
curl_atlas
.
close
()
db_atlas
.
close
()
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment