[英]Importing multiple custom tensor2tensor Problems in Flask
In a flask_restplus API, I'm trying to infer from two tensor2tensor models which are being served on one server. 在flask_restplus API中,我试图从正在一个服务器上服务的两个tensor2tensor模型进行推断。 Both these models are custom, so I am supplying t2t_usr_dir to the serving functions of tensor2tensor, such that the custom Problem could be found.
这两个模型都是自定义的,因此我将t2t_usr_dir提供给tensor2tensor的服务函数,以便可以找到自定义问题。
When inferring on one custom Problem, everything is fine and the results are as expected. 当推断一个自定义问题时,一切都很好,并且结果符合预期。 However, when I want to infer on the second model, the program fails at
但是,当我想推断第二个模型时,程序在
def get_registered_problem(usr_dir_string, problem):
usr_dir.import_usr_dir(usr_dir_string)
print("Importing worked?")
problem = registry.problem(problem)
print("Problem naam:", problem)
return problem
with a LookupError: my_custom_problem_2 not in the set of supported problems
. 与
LookupError: my_custom_problem_2 not in the set of supported problems
。
When I switch back to the first model (my_custom_problem_1), everything is fine again and the logs tell me that an object exists. 当我切换回第一个模型(my_custom_problem_1)时,一切都很好,并且日志告诉我对象存在。 I double checked that all the user and data directories are correct.
我再次检查了所有用户和数据目录是否正确。 It feels like a flask thing OR a
problem = registry.problem(problem)
thing, as if once a custom problem is loaded, the second user directory registration just doesn't get picked up. 感觉就像是一个大
problem = registry.problem(problem)
或者是一个problem = registry.problem(problem)
registration.problem problem = registry.problem(problem)
事情,好像一旦加载了自定义问题,第二个用户目录注册就不会被获取。
Any ideas? 有任何想法吗? Thanks in advance!
提前致谢!
I found out that using the usr_dir.import_usr_dir(usr_dir_string)
is not the best way to go as it seems to indeed re-import the same first usr_dir, as Matthias suggested. 我发现使用
usr_dir.import_usr_dir(usr_dir_string)
并不是最好的方法,因为它确实确实像Matthias所建议的那样重新导入了相同的第一个usr_dir。 I solved this problem by adding the corresponding usr_dirs into my root folder and just importing them as a module. 我通过将相应的usr_dirs添加到我的根文件夹中并将其作为模块导入来解决了此问题。
After that I removed the usr_dir.import_usr_dir(usr_dir_string)
line at all and proceded to register the problem via problem = registry.problem(problem)
, which went fine for both problems! 之后,我完全删除了
usr_dir.import_usr_dir(usr_dir_string)
行,并通过usr_dir.import_usr_dir(usr_dir_string)
problem = registry.problem(problem)
进行了problem = registry.problem(problem)
,对于两个问题都很好!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.