Commit a65da8d1 by BoxuanXu

add mysql clock class

1 parent ff5da1c0
......@@ -16,6 +16,8 @@ from flask import Flask,request
from jenkinsapi.jenkins import Jenkins
from mysql_glock import Mysql_lock
import GProgress as GP
import Queue
......@@ -57,12 +59,20 @@ db_atlas = pymysql.connect("192.168.1.127","defaultUser","magician","seetaAtlas"
curl_atlas = db_atlas.cursor()
curl_atlas_exe = db_atlas.cursor()
db_l = Mysql_lock()
lock_name = 'db_queue'
def get_path_from_db(modelid,seetanet_model):
curl_atlas.execute("select path from seetaAtlas.model where id='%s'" % modelid)
result_atlas = curl_atlas.fetchall()
#curl_atlas.execute("select path from seetaAtlas.model where id='%s'" % modelid)
ret = db_l.lock(lock_name,10)
if ret != True:
logging.info("Can't get lock! exit!")
quit()
ret = db_l._execute("select path from seetaAtlas.model where id='%s'" % modelid)
result_atlas = db_l.cursor.fetchall()
db_l.unlock(lock_name)
if len(result_atlas) != 1:
logging.info('get wrong mxnet model path')
......@@ -119,13 +129,16 @@ def get_path_from_db(modelid,seetanet_model):
GP.set_progress_var(10)
GP.Post_return()
#Driver converter model by params and model graph
#Driver converter model by params and model graph
result = Run_Converter(params_name,graph_name,seetanet_model)
<<<<<<< HEAD
if result is "true":
=======
if result is true:
>>>>>>> ff5da1c0fae179995c0a806eb77fe2667ccc191a
return None,None
#Run_Converter("model-0015.params","model-symbol.json",seetanet_model)
return params_name,graph_name
def upload_filetoFastDFS(params_name, graph_name,seetanet_model):
......
......@@ -64,6 +64,7 @@ class Converter(object):
'Scale': self.convert_scale,
'Activation': self.convert_activation,
'add_n': self.convert_add_n,
'elemwise_add': self.convert_add_n,
'Convolution': self.convert_conv,
'FullyConnected': self.convert_fc,
# 'Flatten': self.convert_bn,
......@@ -238,15 +239,19 @@ class Converter(object):
raise NotImplementedError
pad = parse_tuple(attr['pad'])
# TODO:现在强制VALID=True,后续有mxnet使用其他pool padding的方式时再修改
pool.valid = True
pool.pad_height = pad[0]
pool.pad_width = pad[1]
kernel = parse_tuple(attr['kernel'])
pool.kernel_height = kernel[0]
pool.kernel_width = kernel[1]
stride = parse_tuple(attr['stride'])
pool.stride_height = stride[0]
pool.stride_width = stride[1]
try:
stride = parse_tuple(attr['stride'])
pool.stride_height = stride[0]
pool.stride_width = stride[1]
pad = parse_tuple(attr['pad'])
pool.valid = True
pool.pad_height = pad[0]
pool.pad_width = pad[1]
except:
logging.info('layer: %s is global pooling !!!' % layer.name)
pool.global_pooling = True
pool.stride_height = kernel[0]
pool.stride_width = kernel[1]
return wapper
def convert_activation(self, layer):
......@@ -415,6 +420,9 @@ def Run_Converter(model_param,model_json,seetanet_model):
#parser.add_argument('--model_param',type=str,default = None)
#parser.add_argument('--model_json',type=str,default = None)
#args = parser.parse_args()
#model_param = "wKgB6Fmo2w2ASRqpBky2APcM8zs.params"
#model_json = "wKgB6Vmo2w2AXrJbAAGjO2NrZLE75.json"
#seetanet_model = "model_test"
try:
sym, arg_params, aux_params = \
load_checkpoint(model_param, model_json)
......@@ -426,3 +434,4 @@ def Run_Converter(model_param,model_json,seetanet_model):
return true
except Exception, e:
return None
#print(e)
#!/usr/bin/env python
#_*_ coding: UTF-8 _*_
import pymysql.cursors
import logging
import time
__website__ = "www.seetatech.com"
__author__ = "seetatech"
__editor__ = "xuboxuan"
__Date__ = "20170904"
#initlization the logging
logging.basicConfig(
level=logging.INFO,
format="[%(asctime)s] %(name)s:%(levelname)s: %(message)s"
)
db_atlas = pymysql.connect("192.168.1.127","defaultUser","magician","seetaAtlas",3306)
class Mysql_lock:
def __init__(self):
self.db = db_atlas
self.cursor = db_atlas.cursor()
def _execute(self,sql):
cursor = self.db.cursor()
try:
ret = self.cursor.execute(sql)
return ret
except Exception,ex:
logging.info("Execute sql \"%s\" failed! Exception: %s", sql, str(ex))
#cursor.close()
return None
def lock(self, lockstr, timeout):
sql = "SELECT GET_LOCK('%s', %s)" % (lockstr, timeout)
ret = self._execute(sql)
if ret == 0:
logging.info("Another client has previously locked '%s'.",lockstr)
return False
elif ret == 1:
logging.info("The lock '%s' was obtained successfully.",lockstr)
return True
else:
logging.info("Error occurred!")
return None
def unlock(self, lockstr):
sql = "SELECT RELEASE_LOCK('%s')" % (lockstr)
ret = self._execute(sql)
if ret == 0:
logging.info("The lock '%s' the lock is not released(the lock was not established by this thread).", lockstr)
return False
elif ret == 1:
logging.info("The lock '%s' the lock was released.",lockstr)
return True
else:
logging.info("The lock '%s' did not exist.",lockstr)
return None
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!