Tensorflow错误在笔记本电脑上运行model.fit

时间:2020-07-16 20:34:16

标签: python keras deep-learning conv-neural-network tensorflow2.0

我正在Macbook上训练一维CNN,每当尝试运行文件时,都会出现此错误:

Instructions for updating:
Colocations handled automatically by placer.
2020-07-16 13:27:03.038359: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
Train on 7780 samples, validate on 1945 samples
Traceback (most recent call last):
  File "cnn.py", line 117, in <module>
    model.fit(X_train,y_train, epochs = 100, validation_data = (X_test, y_test), shuffle = True)
  File "/opt/anaconda3/lib/python3.7/site-packages/keras/engine/training.py", line 1239, in fit
    validation_freq=validation_freq)
  File "/opt/anaconda3/lib/python3.7/site-packages/keras/engine/training_arrays.py", line 95, in fit_loop
    steps_name='steps_per_epoch')
  File "/opt/anaconda3/lib/python3.7/site-packages/keras/engine/training_utils.py", line 571, in check_num_samples
    'you should specify the `' + steps_name + '` argument '
ValueError: If your data is in the form of symbolic tensors, you should specify the `steps_per_epoch` argument (instead of the `batch_size` argument, because symbolic tensors are expected to produce batches of input data).

我以前曾经在计算机上训练过CNN,这是第一次。 我的模特在这里:

model = Sequential()
#the shape of the input is (9725, 1000, 1), where there are 9725 training samples and each training sample has 1k features
model.add(Conv1D(filters= 64, kernel_size=3, activation ='relu',strides = 2, padding = 'valid', input_shape= (1000, 1))) 
model.add(MaxPooling1D(pool_size=2))
model.add(Conv1D(filters= 128, kernel_size=3, activation ='relu',strides = 2, padding = 'valid'))
model.add(Dropout(0.5))
model.add(MaxPooling1D(pool_size=2))
model.add(Flatten())
model.add(Dense(21)) #for 21 families
model.add(Activation('softmax'))
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(X_train,y_train, epochs = 100, validation_data = (X_test, y_test), shuffle = True)

0 个答案:

没有答案