MorvanZhou / tutorials

机器学习相关教程
https://morvanzhou.github.io/tutorials
MIT License
11.7k stars 5.71k forks source link

kerasTUT 6-CNN tutorial needs update #44

Closed EmbraceLife closed 7 years ago

EmbraceLife commented 7 years ago

I have tried to update this tutorial to the latest keras. However, it seems the problem to be keras source code, because I tried to use the latest api, but the error it reported is located in keras source.

However, I am a newbie, so I maybe totally wrong. Could you try to update this tutorial, thanks a lot!

I have managed to update part of the tutorial until I met the error:

# Another way to build your CNN
model = Sequential()

# here explain the meaning and effects of number of filters  https://youtu.be/zHop6Oq757Y?list=PLXO45tsB95cKhCSIgTgIfjtG5y0Bf_TIY&t=250
# Conv layer 1 output shape (32, 28, 28)
model.add(Conv2D(
    filters=32,
    data_format='channels_first',
    kernel_size=(5,5),
    padding='same',     # Padding method
    dim_ordering='th',      # if use tensorflow, to set the input dimension order to theano ("th") style, but you can change it.
    input_shape=(1,         # channels
                 28, 28,)    # height & width
))

model.add(Activation('relu'))

# Pooling layer 1 (max pooling) output shape (32, 14, 14)
model.add(MaxPooling2D(
    pool_size=(2, 2),
    strides=(2, 2),
    padding='same'   # Padding method
))

error message I got:

Focus on one: /Users/Natsume/Documents/kur_experiment/LIE_examples/kerasTUT
(dlnd-tf-lab)  ->python 6-CNN_example.py
Using Theano backend.
6-CNN_example.py:58: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(padding="same", data_format="channels_first", kernel_size=(5, 5), filters=32, input_shape=(1, 28, 28...)`
  28, 28,)    # height & width
/Users/Natsume/Downloads/keras/keras/backend/theano_backend.py:1814: UserWarning: dict_keys(['filter_dilation']) are now deprecated in `tensor.nnet.abstract_conv.conv2d` interface and will be ignored.
  filter_dilation=dilation_rate)
Traceback (most recent call last):
  File "6-CNN_example.py", line 67, in <module>
    padding='same'   # Padding method
  File "/Users/Natsume/Downloads/keras/keras/models.py", line 475, in add
    output_tensor = layer(self.outputs[0])
  File "/Users/Natsume/Downloads/keras/keras/engine/topology.py", line 585, in __call__
    output = self.call(inputs, **kwargs)
  File "/Users/Natsume/Downloads/keras/keras/layers/pooling.py", line 154, in call
    data_format=self.data_format)
  File "/Users/Natsume/Downloads/keras/keras/layers/pooling.py", line 217, in _pooling_function
    pool_mode='max')
  File "/Users/Natsume/Downloads/keras/keras/backend/theano_backend.py", line 1945, in pool2d
    mode='max')
TypeError: pool_2d() got an unexpected keyword argument 'ws'
MorvanZhou commented 7 years ago

Thanks, updated