我正在使用 Google Colaboratory 构建神经网络,但是
“顺序”对象没有属性“密集”
不断出现。我尝试过仅使用 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