I am using keras 2.0.2 and trying to run a Conv net
patch_size = 15
print(train_set.shape, 'train samples')
batch_size = 1
nb_classes = 6
nb_epoch = 100
Y_train = np_utils.to_categorical(y_train, nb_classes)
nb_filters = [30, 30]
nb_pool = [2, 2]
nb_conv = [5, 5]
train_set = train_set.astype('float32')
train_set -= np.mean(train_set)
train_set /= np.max(train_set)
model = Sequential()
model.add(Conv3D(nb_filters[0],(nb_conv[0],nb_conv[0],nb_conv[0]),input_shape=(1, img_rows, img_cols, patch_size), activation='relu'))
model.add(MaxPooling3D(pool_size=(nb_pool[0], nb_pool[0], nb_pool[0])))
model.add(Conv3D(nb_filters[0],(nb_conv[0] - 2,nb_conv[0] - 2,nb_conv[0] - 2),input_shape=(1, img_rows, img_cols, patch_size), activation='relu'))
model.add(MaxPooling3D(pool_size=(nb_pool[0], nb_pool[0], nb_pool[0])))
model.add(Conv3D(nb_filters[0],(nb_conv[0]-3, nb_conv[0]-3, nb_conv[0]-3), input_shape=(1, img_rows, img_cols, patch_size), activation='tanh'))
model.add(MaxPooling3D(pool_size=(nb_pool[0], nb_pool[0], nb_pool[0])))
model.add(Conv3D(nb_filters[0],(nb_conv[0]-3, nb_conv[0]-3, nb_conv[0]-3), input_shape=(1, img_rows, img_cols, patch_size), activation='tanh'))
model.add(Dropout(0.5))
model.add(Flatten())
print (model.output_shape)
model.add(Dense(128, kernel_initializer='normal', activation='relu'))
It gives me the train_sample size as = (97, 1, 28, 28, 15)
But then it gives the following error in the dense command
(None,-90)
Traceback (most recent call last):
File "F:/Project/codes/foreg.py", line 144, in <module>
print (model.output_shape)
File "C:\Users\lenov\Anaconda3\envs\3dcnn\lib\site-packages\keras\models.py", line 455, in add
output_tensor = layer(self.outputs[0])
File "C:\Users\lenov\Anaconda3\envs\3dcnn\lib\site-packages\keras\engine\topology.py", line 528, in __call__
self.build(input_shapes[0])
File "C:\Users\lenov\Anaconda3\envs\3dcnn\lib\site-packages\keras\layers\core.py", line 827, in build
constraint=self.kernel_constraint)
File "C:\Users\lenov\Anaconda3\envs\3dcnn\lib\site-packages\keras\engine\topology.py", line 364, in add_weight
weight = K.variable(initializer(shape), dtype=K.floatx(), name=name)
File "C:\Users\lenov\Anaconda3\envs\3dcnn\lib\site-packages\keras\initializers.py", line 73, in __call__
dtype=dtype, seed=self.seed)
File "C:\Users\lenov\Anaconda3\envs\3dcnn\lib\site-packages\keras\backend\theano_backend.py", line 1960, in random_normal
return rng.normal(size=shape, avg=mean, std=stddev, dtype=dtype)
File "C:\Users\lenov\Anaconda3\envs\3dcnn\lib\site-packages\theano\sandbox\rng_mrg.py", line 1574, in normal
nstreams=nstreams)
File "C:\Users\lenov\Anaconda3\envs\3dcnn\lib\site-packages\theano\sandbox\rng_mrg.py", line 1344, in uniform
size)
ValueError: ('The specified size contains a dimension with value <= 0', (-11520,))
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.
Did you ever find a solution to this I'm running into something very like it.
@Simrankgp, @mclark4386,
This looks like a problem with the inputs size :
Using Theano as backend you state the inputs this way : inputs = Input(shape=(3,227,227))
Using Tensorflow as backend : inputs = Input(shape=(227,227,3))
I suggest you to use Theano as backend. Then, in your keras.json, you can adjust "image_data_format": "channels_last" if you want declare in Tensorflow manner.
Most helpful comment
@Simrankgp, @mclark4386,
This looks like a problem with the inputs size :
Using Theano as backend you state the inputs this way : inputs = Input(shape=(3,227,227))
Using Tensorflow as backend : inputs = Input(shape=(227,227,3))
I suggest you to use Theano as backend. Then, in your keras.json, you can adjust "image_data_format": "channels_last" if you want declare in Tensorflow manner.