Hi, I just got an error from my daily test, raised via a new tf version with Keras3.
In brief
Since we have pinned tensorflow as ^2.5.0, newly installed environment will always require the latest version, which does not allow this operation.
Detailed error message
File "/home/runner/miniconda3/envs/REvoDesign/lib/python3.11/site-packages/joblib/parallel.py", line 589, in <listcomp>
return [func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/work/REvoDesign/REvoDesign/REvoDesign/common/MutantVisualizer.py", line 93, in process_mutant
temp_session_path = self.create_mutagenesis_objects(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/work/REvoDesign/REvoDesign/REvoDesign/common/MutantVisualizer.py", line 136, in create_mutagenesis_objects
temp_mutant_pdb_path = self.mutate_runner.run_mutate(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/work/REvoDesign/REvoDesign/REvoDesign/sidechain_solver/DLPacker.py", line 89, in run_mutate
self.dlpacker_worker = DLPacker(str_pdb=self.pdb_file)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/miniconda3/envs/REvoDesign/lib/python3.11/site-packages/DLPacker/dlpacker.py", line 124, in __init__
self.model = DLPModel(width=128, nres=6)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/miniconda3/envs/REvoDesign/lib/python3.11/site-packages/DLPacker/utils.py", line 203, in __init__
self.model = self.model()
^^^^^^^^^^^^
File "/home/runner/miniconda3/envs/REvoDesign/lib/python3.11/site-packages/DLPacker/utils.py", line 320, in model
fc = tf.reshape(
^^^^^^^^^^^
File "/home/runner/miniconda3/envs/REvoDesign/lib/python3.11/site-packages/tensorflow/python/ops/weak_tensor_ops.py", line 88, in wrapper
return op(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/home/runner/miniconda3/envs/REvoDesign/lib/python3.11/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/home/runner/miniconda3/envs/REvoDesign/lib/python3.11/site-packages/keras/src/backend/common/keras_tensor.py", line 92, in __tf_tensor__
raise ValueError(
ValueError: A KerasTensor cannot be used as input to a TensorFlow function. A KerasTensor is a symbolic placeholder for a shape and dtype, used when constructing Keras Functional models or Keras Functions. You can only use it as input to a Keras layer or a Keras operation (from the namespaces `keras.layers` and `keras.operations`). You are likely doing something like:
\```
x = Input(...)
...
tf_fn(x) # Invalid.
\```
What you should do instead is wrap `tf_fn` in a layer:
\```
class MyLayer(Layer):
def call(self, x):
return tf_fn(x)
x = MyLayer()(x)
\```
my fix attempt here is use fc = K.ops.reshape(fc, (-1, self.grid_size, self.grid_size, self.grid_size, 1)) instead, and it works from py39-311.
Update:
tf 2.15.0 vs K.ops.reshape(macos with m1 chips):
File "/Users/yyy/Documents/protein_design/REvoDesign/REvoDesign/common/MutantVisualizer.py", line 136, in create_mutagenesis_objects
temp_mutant_pdb_path = self.mutate_runner.run_mutate(
File "/Users/yyy/Documents/protein_design/REvoDesign/REvoDesign/sidechain_solver/DLPacker.py", line 89, in run_mutate
self.dlpacker_worker = DLPacker(str_pdb=self.pdb_file)
File "/Users/yyy/miniconda_py39_arm64/lib/python3.10/site-packages/DLPacker/dlpacker.py", line 124, in __init__
self.model = DLPModel(width=128, nres=6)
File "/Users/yyy/miniconda_py39_arm64/lib/python3.10/site-packages/DLPacker/utils.py", line 204, in __init__
self.model = self.model()
File "/Users/yyy/miniconda_py39_arm64/lib/python3.10/site-packages/DLPacker/utils.py", line 323, in model
fc = K.ops.reshape(fc, (-1, self.grid_size, self.grid_size, self.grid_size, 1))
AttributeError: module 'tensorflow.keras' has no attribute 'ops'
Update -2
currently tensorflow-macos does not have >=2.16.0 and pip may complain if we install tensorflow-macos after tensorflow >=2.16.0 and keras >=3. bui it is total fine.
so i think we have two options for this:
pining tensorflow: >=2.5.0, <2.16.0, with no code change
Hi, I just got an error from my daily test, raised via a new tf version with Keras3.
In brief
Since we have pinned tensorflow as
^2.5.0
, newly installed environment will always require the latest version, which does not allow this operation.Detailed error message
Affected code
https://github.com/nekitmm/DLPacker/blob/cb79d2933d2e6822edfefc20313e0beecfe05b46/dlpacker/utils.py#L357
Possible fix
my fix attempt here is use
fc = K.ops.reshape(fc, (-1, self.grid_size, self.grid_size, self.grid_size, 1))
instead, and it works from py39-311.Update:
tf 2.15.0
vsK.ops.reshape
(macos with m1 chips):Update -2
currently
tensorflow-macos
does not have>=2.16.0
and pip may complain if we installtensorflow-macos
aftertensorflow >=2.16.0
andkeras >=3
. bui it is total fine.so i think we have two options for this:
tensorflow
:>=2.5.0, <2.16.0
, with no code changetensorflow
:>=2.16.0
, with the above fix and remove legacy adam optimizer calling: https://github.com/nekitmm/DLPacker/blob/cb79d2933d2e6822edfefc20313e0beecfe05b46/dlpacker/utils.py#L236Useful links
https://keras.io/guides/migrating_to_keras_3/ https://keras.io/api/ops/numpy/#reshape-function