NameError: name 'tf' is not defined

NameError: name 'tf' is not defined

报错如下:


/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/layers/core.py in <lambda>(x)
    307       It defaults to the `image_data_format` value found in your
    308       Keras config file at `~/.keras/keras.json`.
--> 309       If you never set it, then it will be "channels_last".
    310 
    311   Call arguments:

NameError: name 'tf' is not defined


这个报错比较奇怪,定位到是执行到如下语句的报错:

tf.keras.models.load_model(MODEL_PATH)

之前遇到过几次,我试了下主要有两种解决方式是:

第一种解决方式是重新拉取MODEL_PATH的文件,可能在拉取过程中发生一些文件损坏。

第二种解决方式是,观察报错,提示 name 'tf' is not defined,说明内部没有将tensorflow这个库传入内部当中,用以下语句进行解决:

tf.keras.models.load_model(MODEL_PATH, custom_objects={'tf': tf})
posted @   NoMornings  阅读(626)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】

喜欢请打赏

扫描二维码打赏

支付宝打赏

点击右上角即可分享
微信分享提示