Keras:Bug取决于网络中的层数

时间:2018-07-29 09:02:42

标签: tensorflow keras

在使用keras时,我遇到了看似随意的错误。尝试在keras中建立模型时,我遇到错误“ NotFoundError:FeedInputs:无法找到提要输出density_3_target:0”。错误似乎取决于我放入网络的层数(当层数不等于4时出错)。有人知道这是怎么回事吗?

代码和错误消息:

if (addressList != null && addressList.size() != 0) {
         AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
         builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener)
        .setNegativeButton("No", dialogClickListener).show();
        } else {
            Toast.makeText(getApplicationContext(), "location not found", Toast.LENGTH_SHORT).show();
        }

================================================ ====================

import tensorflow as tf
import numpy as np

import keras
from keras.models import Sequential
from keras.layers import Dense

tf.reset_default_graph()


from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("mnist", one_hot=True)

X_train = mnist.train.images
y_train = mnist.train.labels
X_test = mnist.test.images
y_test = mnist.test.labels


# Hyper Parameters
n_features = 784
n_classes = 10
learning_rate = 0.5
training_epochs = 2


model = Sequential()
model.add(Dense(units = 100, activation = 'relu', input_dim = n_features))
model.add(Dense(units = 50,activation = 'relu'))
model.add(Dense(50,activation = 'relu'))
model.add(Dense(units = n_classes, activation = 'softmax'))

# Step 3: Compile the Model
model.compile(optimizer='adam',loss='categorical_crossentropy')

## Step 4: Train the Model
history = model.fit(X_train,y_train,epochs=10,batch_size = 100,validation_data=(X_test,y_test))

0 个答案:

没有答案