image-super-resolution icon indicating copy to clipboard operation
image-super-resolution copied to clipboard

While predicting this error is raised

Open mohdtanweer opened this issue 4 years ago • 2 comments

I have trained my own model and I'm able to predict in single images. But I'm unable to use predictor class to run on the model on entire image of input directory. Failing in predictor.get_predictions() method with below error: ConstructorError: while constructing a Python object module 'ISR.utils.metrics' is not imported in "", line 25, column 26: metrics: {generator: !!python/name:ISR.utils.metrics. ...

mohdtanweer avatar Jul 22 '19 14:07 mohdtanweer

I get similar error when trying to run predictions on docker locally:

Hello. This is your favorite ISR assistant.

Loaded weights from weights/rdn-C6-D20-G64-G064-x2/2020-01-28_2058/rdn-C6-D20-G64-G064-x2_epoch300.hdf5 Traceback (most recent call last): File "/home/isr/ISR/assistant.py", line 90, in prediction=args['prediction'], File "/home/isr/ISR/assistant.py", line 28, in run pr_h.get_predictions(gen, conf['weights_paths']['generator']) File "/home/isr/ISR/predict/predictor.py", line 85, in get_predictions weights_conf = self._load_weights() File "/home/isr/ISR/predict/predictor.py", line 65, in _load_weights conf = yaml.load(session_config_path.read_text(), Loader=yaml.FullLoader) File "/usr/local/lib/python3.6/dist-packages/yaml/init.py", line 114, in load return loader.get_single_data() File "/usr/local/lib/python3.6/dist-packages/yaml/constructor.py", line 43, in get_single_data return self.construct_document(node) File "/usr/local/lib/python3.6/dist-packages/yaml/constructor.py", line 52, in construct_document for dummy in generator: File "/usr/local/lib/python3.6/dist-packages/yaml/constructor.py", line 405, in construct_yaml_map value = self.construct_mapping(node) File "/usr/local/lib/python3.6/dist-packages/yaml/constructor.py", line 210, in construct_mapping return super().construct_mapping(node, deep=deep) File "/usr/local/lib/python3.6/dist-packages/yaml/constructor.py", line 135, in construct_mapping value = self.construct_object(value_node, deep=deep) File "/usr/local/lib/python3.6/dist-packages/yaml/constructor.py", line 94, in construct_object data = constructor(self, tag_suffix, node) File "/usr/local/lib/python3.6/dist-packages/yaml/constructor.py", line 552, in construct_python_name return self.find_python_name(suffix, node.start_mark) File "/usr/local/lib/python3.6/dist-packages/yaml/constructor.py", line 539, in find_python_name "module %r is not imported" % module_name, mark) yaml.constructor.ConstructorError: while constructing a Python object module 'ISR.utils.metrics' is not imported in "", line 53, column 18: generator: !!python/name:ISR.utils.metrics. ... ``

Olivier222 avatar Jan 29 '20 19:01 Olivier222

This issue seems related to a missing import in predictor.py. As the error states you need to import also ISR.utils.metrics since is that module is required in your yaml configuration file.

In my case adding from ISR.utils.metrics import PSNR_Y at line 10 solved the problem

https://github.com/idealo/image-super-resolution/blob/3f6498cf1ac4dba162a52c5861aa9d90b7c2fe35/ISR/predict/predictor.py#L1-L13

erikyo avatar Aug 05 '22 18:08 erikyo