资源简介
TensorFlow训练mask_rcnn模型,生成pb文件后转成pbtxt文件,opencv4.0.1调用
代码片段和文件信息
def tokenize(s):
tokens = []
token = ““
isString = False
isComment = False
for symbol in s:
isComment = (isComment and symbol != ‘\n‘) or (not isString and symbol == ‘#‘)
if isComment:
continue
if symbol == ‘ ‘ or symbol == ‘\t‘ or symbol == ‘\r‘ or symbol == ‘\‘‘ or \
symbol == ‘\n‘ or symbol == ‘:‘ or symbol == ‘\“‘ or symbol == ‘;‘ or \
symbol == ‘‘:
if (symbol == ‘\“‘ or symbol == ‘\‘‘) and isString:
tokens.append(token)
token = ““
else:
if isString:
token += symbol
elif token:
tokens.append(token)
token = ““
isString = (symbol == ‘\“‘ or symbol == ‘\‘‘) ^ isString;
elif symbol == ‘{‘ or symbol == ‘}‘ or symbol == ‘[‘ or symbol == ‘]‘:
if token:
tokens.append(token)
token = ““
tokens.append(symbol)
else:
token += symbol
if token:
tokens.append(token)
return tokens
def parseMessage(tokens idx):
msg = {}
assert(tokens[idx] == ‘{‘)
isArray = False
while True:
if not isArray:
idx += 1
if idx < len(tokens):
fieldName = tokens[idx]
else:
return None
if fieldName == ‘}‘:
break
idx += 1
fieldValue = tokens[idx]
if fieldValue == ‘{‘:
embeddedMsg idx = parseMessage(tokens idx)
if fieldName in msg:
msg[fieldName].append(embeddedMsg)
else:
msg[fieldName] = [embeddedMsg]
elif fieldValue == ‘[‘:
isArray = True
elif fieldValue == ‘]‘:
isArray = False
else:
if fieldName in msg:
msg[fieldName].append(fieldValue)
else:
msg[fieldName] = [fieldValue]
return msg idx
def readTextMessage(filePath):
if not filePath:
return {}
with open(filePath ‘rt‘) as f:
content = f.read()
tokens = tokenize(‘{‘ + content + ‘}‘)
msg = parseMessage(tokens 0)
return msg[0] if msg else {}
def listToTensor(values):
if all([isinstance(v float) for v in values]):
dtype = ‘DT_FLOAT‘
field = ‘float_val‘
elif all([isinstance(v int) for v in values]):
dtype = ‘DT_INT32‘
field = ‘int_val‘
else:
raise Exception(‘Wrong values types‘)
msg = {
‘tensor‘: {
‘dtype‘: dtype
‘tensor_shape‘: {
‘dim‘: {
‘size‘: len(values)
}
}
}
}
msg[‘tensor‘][field] = values
return msg
def addConstNode(name values graph_def):
node
- 上一篇:helmert方差分量估计程序
- 下一篇:STM32读写时钟PCF8563
评论
共有 条评论