我是神经网络新手,正在使用 google colab 构建神经网络。但“‘顺序’对象没有属性‘密集’”不断出现,我尝试仅使用 Keras 而不是混合库。下面是我的代码,请帮助我,此时我非常绝望。
import tensorflow as tf
from tensorflow import keras
from keras.models import Sequential
from keras.layers import Flatten, Conv2D, MaxPooling2D, Dropout, Dense
from keras import layers
from keras.utils import to_categorical
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
model = Sequential()
model.add(Conv2D(32, (5,5), activation='relu', input_shape=(32,32,3)))
model.add(MaxPooling2D(pool_size = (2,2)))
model.add(Conv2D(32, (5,5), activation='relu'))
model.add(MaxPooling2D(pool_size = (2,2)))
model.add(Flatten())
model.Dense(1000, activation='relu')
model.add(Dropout(0.5))
model.Dense(500, activation='relu')
model.add(Droptout(0.5))
model.Dense(250, activation='relu')
model.Dense(10, activation='softmax')
而不是使用
model.Dense(1000,激活='relu')
使用
model.add(密集(1000,激活='relu'))
应该是 model.add(Dense(...)) 而不是 model.Dense
也许添加这一行会有帮助
from tensorflow.keras.layers import Dense