Skip to content

Instantly share code, notes, and snippets.

@kylemcdonald
Created January 30, 2016 05:26
Show Gist options
  • Save kylemcdonald/ff2aaa33b78f9fb48867 to your computer and use it in GitHub Desktop.
Save kylemcdonald/ff2aaa33b78f9fb48867 to your computer and use it in GitHub Desktop.
A bug in Keras?
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using Theano backend.\n",
"Using gpu device 0: GeForce GT 750M (CNMeM is enabled)\n",
"/usr/local/lib/python2.7/site-packages/theano/tensor/signal/downsample.py:5: UserWarning: downsample module has been moved to the pool module.\n",
" warnings.warn(\"downsample module has been moved to the pool module.\")\n"
]
}
],
"source": [
"import keras\n",
"from keras.models import Sequential\n",
"from keras.layers.core import Flatten\n",
"from keras.layers.convolutional import Convolution1D, MaxPooling1D\n",
"from keras.layers.convolutional import Convolution2D, MaxPooling2D"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--------------------------------------------------------------------------------\n",
"Initial input shape: (None, 1, 28, 28)\n",
"--------------------------------------------------------------------------------\n",
"Layer (name) Output Shape Param # \n",
"--------------------------------------------------------------------------------\n",
"Convolution2D (convolution2d) (None, 32, 28, 28) 320 \n",
"MaxPooling2D (maxpooling2d) (None, 32, 14, 14) 0 \n",
"Convolution2D (convolution2d) (None, 32, 12, 12) 9248 \n",
"MaxPooling2D (maxpooling2d) (None, 32, 6, 6) 0 \n",
"--------------------------------------------------------------------------------\n",
"Total params: 9568\n",
"--------------------------------------------------------------------------------\n",
"None\n",
"--------------------------------------------------------------------------------\n",
"Initial input shape: (None, 1, 28)\n",
"--------------------------------------------------------------------------------\n",
"Layer (name) Output Shape Param # \n",
"--------------------------------------------------------------------------------\n",
"Convolution1D (convolution1d) (None, 1, 32) 2720 \n",
"MaxPooling1D (maxpooling1d) (None, 0, 32) 0 \n",
"Convolution1D (convolution1d) (None, -2, 32) 3104 \n",
"MaxPooling1D (maxpooling1d) (None, -1, 32) 0 \n",
"--------------------------------------------------------------------------------\n",
"Total params: 5824\n",
"--------------------------------------------------------------------------------\n",
"None\n"
]
}
],
"source": [
"nb_filters = 32\n",
"nb_conv = 3\n",
"nb_pool = 2\n",
"length = 28\n",
"\n",
"model = Sequential()\n",
"model.add(Convolution2D(nb_filters, nb_conv, nb_conv,\n",
" border_mode='same',\n",
" input_shape=(1, length, length)))\n",
"model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))\n",
"model.add(Convolution2D(nb_filters, nb_conv, nb_conv))\n",
"model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))\n",
"print model.summary()\n",
"\n",
"model = Sequential()\n",
"model.add(Convolution1D(nb_filters, nb_conv,\n",
" border_mode='same',\n",
" input_shape=(1, length)))\n",
"model.add(MaxPooling1D(pool_length=nb_pool))\n",
"model.add(Convolution1D(nb_filters, nb_conv))\n",
"model.add(MaxPooling1D(pool_length=nb_pool))\n",
"print model.summary()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
@luthfianto
Copy link

Hi, I have a question. Suppose I have a dataframe of 23347 rows x 380 columns. What is the correct input_shape for Convolution1D? with (1, 380) and (None, 380), I can't get the model to compile.

But if I use (10, 380), my model compiles but I can't fit it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment