openvax / mhcflurry

Peptide-MHC I binding affinity prediction
http://openvax.github.io/mhcflurry/
Apache License 2.0
191 stars 57 forks source link

Running mhc-flurry predict returns error: ValueError: Both `input_dim` and `output_dim` should be positive, found input_dim 0 and output_dim 777 #187

Closed liscruk closed 3 years ago

liscruk commented 3 years ago

When installing with conda, this error gets raised when system version of python is greater than 3.8.8. Even with an activated conda environment mhc-flurry still might default to system python. This is fixable simply changing the shebang:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from mhcflurry.predict_command import run
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(run())

to

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import sys
from mhcflurry.predict_command import run
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(run())

In case anybody else has this issue. It might be an easy minor "fix" for future version and of course QOL addition.

Full error message:

File "/.local/bin/mhcflurry-predict", line 8, in <module> sys.exit(run())
File "/.local/lib/python3.9/site-packages/mhcflurry/predict_command.py", line 204, in run predictor = Class1PresentationPredictor.load(models_dir)
File "/.local/lib/python3.9/site-packages/mhcflurry/class1_presentation_predictor.py", line 956, in loadaffinity_predictor = Class1AffinityPredictor.load(
File "/.local/lib/python3.9/site-packages/mhcflurry/class1_affinity_predictor.py", line 549, in loadoptimized = result.optimize()
File "/.local/lib/python3.9/site-packages/mhcflurry/class1_affinity_predictor.py", line 594, in optimizeClass1NeuralNetwork.merge(
File "/.local/lib/python3.9/site-packages/mhcflurry/class1_neural_network.py", line 1126, in mergenetworks = [
File "/.local/lib/python3.9/site-packages/mhcflurry/class1_neural_network.py", line 1127, in <listcomp>model.network() for model in models
File "/.local/lib/python3.9/site-packages/mhcflurry/class1_neural_network.py", line 264, in networkself._network = keras.models.model_from_json(self.network_json)
File "/.local/lib/python3.9/site-packages/tensorflow/python/keras/saving/model_config.py", line 126, in model_from_jsonreturn deserialize(config, custom_objects=custom_objects)
File "/.local/lib/python3.9/site-packages/tensorflow/python/keras/layers/serialization.py", line 159, in deserializereturn generic_utils.deserialize_keras_object(
File "/.local/lib/python3.9/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 668, in deserialize_keras_objectdeserialized_obj = cls.from_config(
File "/.local/lib/python3.9/site-packages/tensorflow/python/keras/engine/training.py", line 2357, in from_configfunctional.reconstruct_from_config(config, custom_objects))
File "/.local/lib/python3.9/site-packages/tensorflow/python/keras/engine/functional.py", line 1279, in reconstruct_from_configprocess_layer(layer_data)
File "/.local/lib/python3.9/site-packages/tensorflow/python/keras/engine/functional.py", line 1261, in process_layerlayer = deserialize_layer(layer_data, custom_objects=custom_objects)
File "/.local/lib/python3.9/site-packages/tensorflow/python/keras/layers/serialization.py", line 159, in deserializereturn generic_utils.deserialize_keras_object(
File "/.local/lib/python3.9/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 675, in deserialize_keras_objectdeserialized_obj = cls.from_config(cls_config)
File "/.local/lib/python3.9/site-packages/tensorflow/python/keras/engine/base_layer.py", line 740, in from_configreturn cls(**config)
File "/.local/lib/python3.9/site-packages/tensorflow/python/keras/layers/embeddings.py", line 103, in __init__raise ValueError('Both `input_dim` and `output_dim` should be positive, '
ValueError: Both `input_dim` and `output_dim` should be positive, found input_dim 0 and output_dim 77
timodonnell commented 3 years ago

Hi there, thanks for submitting this. This error happens when tensorflow >= 2.3.0 is used, due to a change in tensorflow that occurred after tensorflow 2.2.0. The fix requires re-training the models, so it's a known issue until we release the next version of the MHCflurry models. The files with the shebang are generated automatically when the package is installed. I think your change is likely changing the venv bieng used and thus the version of tensorflow.

liscruk commented 3 years ago

Hi thanks for your response! Problem for me was that I had all the older versions installed in a conda env but for some reason on our server we still defaulted to the sys version of the packages so there might also be an issue with the python envs on our end. I just wanted to leave it here in case people get the error even with correct dependencies and want to put a band aid on it.

Thanks for your help and your input.