多类图像场景分类

时间:2019-02-21 16:19:42

标签: tensorflow image-processing deep-learning data-science

我正在对场景进行分类,但是我没有得到正确的分类,请 帮助我如何对图像进行分类。 , 我正在创建像这样的字典,我想对像这样的图像进行分类。

label_dict={'0':'buildings', 

'1':'forest',

'2':'glacier',

'3':'mountain',

'4':'sea' ,

'5':'street' }

我正在建立像这样的模型

model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3),
                 strides=2,
                 activation='relu',
                 input_shape=(32, 32, 3)))
model.add(Dropout(0.5))
model.add(Conv2D(32, kernel_size=(3, 3), strides=2, activation='relu'))
model.add(Dropout(0.5))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dense(10, activation='softmax'))

model.compile(loss=keras.losses.categorical_crossentropy,
              optimizer='adam',
              metrics=['accuracy'])

model.summary()

但是我遇到了这样的错误

ValueError                                Traceback (most recent call last)
<ipython-input-16-4f5a963b4f20> in <module>
      1 model.fit(x_train, y_train,
      2           batch_size=128,
----> 3           epochs=5 ,validation_data=(x_test, y_test))

~/anaconda3/lib/python3.7/site-packages/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)
    950             sample_weight=sample_weight,
    951             class_weight=class_weight,
--> 952             batch_size=batch_size)
    953         # Prepare validation data.
    954         do_validation = False

~/anaconda3/lib/python3.7/site-packages/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_array_lengths, batch_size)
    787                 feed_output_shapes,
    788                 check_batch_axis=False,  # Don't enforce the batch size.
--> 789                 exception_prefix='target')
    790 
    791             # Generate sample-wise weight values given the `sample_weight` and

~/anaconda3/lib/python3.7/site-packages/keras/engine/training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
    136                             ': expected ' + names[i] + ' to have shape ' +
    137                             str(shape) + ' but got array with shape ' +
--> 138                             str(data_shape))
    139     return data
    140 

ValueError: Error when checking target: expected dense_2 to have shape (10,) but got array with shape (6,)

我被应用于这些密集的第6层输入,但是我没有得到正确的分类

这些是我的JupyterNotebook链接 http://localhost:8888/notebooks/intel%20image%20classification.ipynb

0 个答案:

没有答案