Hi,
Question
I’m new to TensorFlow and am trying to deploy the model trained by another lab. They used TensorFlow v.2.8 but, to have TensorFlow running on my MacBook (M1 chip), I installed v.2.16 in the virtual environment. This difference in TensorFlow version gave me an issue as they have a line: from tensorflow.keras.backend import function
that keeps giving me import error.
What I tried
- I tried to install v. 2.8 on Macbook but the kernel in Jupyter notebook keeps crashing and restarting.
- I tried to find the equivalent function in v.2.16 but cannot find it.
I wonder if there is a way for me to 1) either run v.2.8 on M1 Mac or 2) resolve the import issue when running from tensorflow.keras.backend import function
Thank you very much for helping
“Modified by moderator”
Hi @Katherine Welcome to the Tensorflow Forum ,
It seems like you’re encountering compatibility issues due to the difference in TensorFlow versions between your environment and the one used by the lab. Here are some potential solutions to consider:
Virtual Environment with TensorFlow 2.8
- If possible, try creating a virtual environment specifically for this project with TensorFlow 2.8 installed. This can help avoid conflicts with other versions of TensorFlow.
- Ensure that you’re using the correct pip command to install TensorFlow 2.8. You can specify the version using:
Create a new Conda environment
conda create --name tf2.8 python=3.8
conda activate tf2.8
Install TensorFlow
pip install tensorflow-macos==2.8
Resolving Import Error
- The
tensorflow.keras.backend.function
function might have been deprecated or removed in TensorFlow 2.16. You can try using an alternative approach to achieve the same functionality. For example, you can use tf.function
decorator to create TensorFlow graphs from Python functions. Here’s an example:
import tensorflow as tf
@tf.function
def my_function(inputs):
# You can Write your code here
return outputs
# Call the function
result = my_function(input_data)
Thank You !