In a flask_restplus API, I'm trying to infer from two tensor2tensor models which are being served on one server. 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.
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
.
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. 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.
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. I solved this problem by adding the corresponding usr_dirs into my root folder and just importing them as a module.
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!