import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.models import load_model
newmodel = tf.keras.models.load_model(file)
发生 NameError: name 'tf' is not defined 错误
添加
custom_objects={'tf': tf}
newmodel = tf.keras.models.load_model(file,custom_objects={'tf': tf})