代码拉取完成,页面将自动刷新
同步操作将从 kerlomz/captcha_platform 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Author: kerlomz <[email protected]>
import os
import time
from graph_session import GraphSession
from predict import predict_func
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
class Interface(object):
def __init__(self, graph_session: GraphSession):
self.graph_sess = graph_session
self.model_conf = graph_session.model_conf
self.size_str = self.model_conf.size_string
self.graph_name = self.graph_sess.graph_name
self.version = self.graph_sess.version
self.model_category = self.model_conf.category_param
if self.graph_sess.loaded:
self.sess = self.graph_sess.session
self.dense_decoded = self.sess.graph.get_tensor_by_name("dense_decoded:0")
self.x = self.sess.graph.get_tensor_by_name('input:0')
self.sess.graph.finalize()
@property
def name(self):
return self.graph_name
@property
def size(self):
return self.size_str
def destroy(self):
self.graph_sess.destroy()
def predict_batch(self, image_batch, output_split=None):
predict_text = predict_func(
image_batch,
self.sess,
self.dense_decoded,
self.x,
self.model_conf,
output_split
)
return predict_text
class InterfaceManager(object):
def __init__(self, interface: Interface = None):
self.group = []
self.invalid_group = {}
self.set_default(interface)
def add(self, interface: Interface):
if interface in self.group:
return
self.group.append(interface)
def remove(self, interface: Interface):
if interface in self.group:
interface.destroy()
self.group.remove(interface)
def report(self, model):
self.invalid_group[model] = {"create_time": time.asctime(time.localtime(time.time()))}
def remove_by_name(self, graph_name):
interface = self.get_by_name(graph_name, False)
self.remove(interface)
def get_by_size(self, size: str, return_default=True):
match_ids = [i for i in range(len(self.group)) if self.group[i].size_str == size]
if not match_ids:
return self.default if return_default else None
else:
ver = [self.group[i].version for i in match_ids]
return self.group[match_ids[ver.index(max(ver))]]
def get_by_name(self, key: str, return_default=True):
for interface in self.group:
if interface.name == key:
return interface
return self.default if return_default else None
@property
def default(self):
return self.group[0] if len(self.group) > 0 else None
@property
def default_name(self):
_default = self.default
if not _default:
return
return _default.graph_name
@property
def total(self):
return len(self.group)
@property
def online_names(self):
return [i.name for i in self.group]
def set_default(self, interface: Interface):
if not interface:
return
self.group.insert(0, interface)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。