日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ValueError: This model has not yet been built. Build the model first by calling build() or calling f

發布時間:2025/3/19 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ValueError: This model has not yet been built. Build the model first by calling build() or calling f 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

ValueError: This model has not yet been built. Build the model first by calling build() or calling fit() with some data. Or specify input_shape or batch_input_shape in the first layer for automatic build.? 報錯原因

?

1、keras建模有3種實現方式——序列模型、函數模型、子類模型。

?序列模型:即通過Sequential方式,初始創建Sequential對象,然后一層一層add添加層結構

函數模型:在函數內部,創建一層一層的layers,然后通過Sequential封裝返回,Sequential此時會自動調用build函數,構建模型,后期我們不需要在調用model.build(input_shape)。這里的函數模型其實更強調是layer,而不是Model,這種方式也可以通過類的方式來寫,只不過此時要繼承layer.Layer,然后再調用時,創建完類對象后,要用Sequential封裝一下。

子類模型:通過類的方式定義神經網絡,此時一般繼承自tf.keras.Model,然后在其他地方通過創建類創建神經網絡

?

2、為何會報錯

這種錯誤一般會出現在子類模型中,通過子類方式創建并不會默認調用build函數,需要我們自己調用build函數進行構建

model.build(input_shape) # `input_shape` is the shape of the input data, e.g. input_shape = (None, 32, 32, 3)

當然,也可將model.summary() 放在model.fit() 后面,此時不用調用model.buile() 也不會報錯

?

3、參考

https://blog.csdn.net/weixin_39190382/article/details/109322296

https://blog.csdn.net/sisiel/article/details/103163016

https://stackoverflow.com/questions/55908188/this-model-has-not-yet-been-built-error-on-model-summary/64564990#64564990

https://blog.csdn.net/m0_37602827/article/details/104740696?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

?

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的ValueError: This model has not yet been built. Build the model first by calling build() or calling f的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。