nas = keras.applications.nasnet.NASNetLarge(input_shape=(331,331,3), include_top=False, weights='imagenet',pooling="avg")先后报错内容:
解决方法:module 'keras.applications' has no attribute 'nasnet'
module 'keras' has no attribute 'applications'
cannot import name 'binary_focal_crossentropy' from 'keras.backend'
Another metric with the same name already exists.
keras被tensorflow收购后一些旧版本的包嵌套关系不适用,因此最终解决步骤为:
1 首先卸载现有的tensorflow和keras
2 重新安装最新版的tensorflow,我安装的2.8.0版本
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow-cpu==2.8.0
3 代码修改为
import tensorflow as tf
tf.keras.applications.nasnet.NASNetLarge()
import tensorflow as tf nas = tf.keras.applications.nasnet.NASNetLarge(input_shape=(331,331,3), include_top=False, weights='imagenet',pooling="avg")



