亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

向 CNN 添加完全連接的層

向 CNN 添加完全連接的層

小怪獸愛吃肉 2023-02-22 19:03:39
我想在這個 CNN 架構中添加一個全局平均池化層,然后是幾個完全連接的層:img_input = layers.Input(shape=(img_size, img_size, 1))x = layers.Conv2D(16, (3,3), activation='relu', strides = 1, padding = 'same')(img_input)x = layers.MaxPool2D(pool_size=2)(x)x = layers.Conv2D(32, (3,3), activation='relu', strides = 2)(x)x = layers.MaxPool2D(pool_size=2)(x)x = layers.Conv2D(64, (3,3), activation='relu', strides = 2)(x)x = layers.MaxPool2D(pool_size=2)(x)x = layers.Conv2D(3, 5, activation='relu', strides = 2)(x)x = layers.Dense(200,activation='relu')x = layers.Dropout(0.1)output = layers.Flatten()(x)model = Model(img_input, output)model.summary()但是每當我嘗試在 las Conv2D 層之后添加一個完全連接的層時,我都會收到以下錯誤:---------------------------------------------------------------------------AttributeError                            Traceback (most recent call last)<ipython-input-370-1cf54963b964> in <module>     11 x = layers.Dropout(0.1)     12 ---> 13 output = layers.Flatten()(x)     14      15 model = Model(img_input, output)/usr/local/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py in __call__(self, inputs, *args, **kwargs)    885         # Eager execution on data tensors.    886         with backend.name_scope(self._name_scope()):--> 887           self._maybe_build(inputs)    888           cast_inputs = self._maybe_cast_inputs(inputs)    889           with base_layer_utils.autocast_context_manager(/usr/local/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py in _maybe_build(self, inputs)   2120     if not self.built:   2121       input_spec.assert_input_compatibility(-> 2122           self.input_spec, inputs, self.name)   2123       input_list = nest.flatten(inputs)   2124       if input_list and self._dtype_policy.compute_dtype is None:我的數據集如下所示:print(X_train.shape, X_test.shape, Y_train.shape, Y_test.shape)(1600, 200, 200, 1) (400, 200, 200, 1) (1600, 3) (400, 3)我在這里錯過了什么?
查看完整描述

1 回答

?
慕妹3146593

TA貢獻1820條經驗 獲得超9個贊

當您使用函數式 API 時,您想要使用:

x = layers.Dense(200, activation='relu')(x)
x = layers.Dropout(0.1)(x)


查看完整回答
反對 回復 2023-02-22
  • 1 回答
  • 0 關注
  • 102 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號