I'm trying to use Keras w/TensorFlow (Python3) backend to build a Convolutional NN for NLP classification. The issue I'm having is when in the defining the shape of my input when building my network. I'm correctly following their API (not my first time using Keras) yet I am getting a variety of inexplicable errors.
This is my Network configuration:
convoNet = Sequential()
convoNet.add(Conv2D(10, (29, 3), input_shape=(None, maxRow, 29, 1)))
convoNet.add(MaxPooling2D(pool_size=(2, 2)))
convoNet.add(Dropout(.5))
convoNet.add(Dense(2, activation='softmax’))
convoNet.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=['accuracy'])
convoNet.fit(trainingSet[0], trainLabels, nb_epoch=20, batch_size=10)
scores = convoNet.evaluate(testingSet[0], testLabels)
print("\n", scores)
And I get this Error:
Traceback (most recent call last):
File "/Users/bl755p/Documents/WRT_NLP.py", line 646, in <module>
convoNet.add(Conv2D(10, (29, 3), input_shape=(None, maxRow, 29, 1)))
TypeError: __init__() missing 1 required positional argument: ‘nb_col'
And I’ve also tried this (Only thing that changes is Conv2D so just gonna show you that):
convoNet.add(Conv2D(10, (29, 3), nb_row=maxRow, nb_col=29))
And got this error:
Traceback (most recent call last):
File "/Users/bl755p/Documents/WRT_NLP.py", line 646, in <module>
convoNet.add(Conv2D(10, (29, 3), nb_row=maxRow, nb_col=29))
TypeError: __init__() got multiple values for argument 'nb_row'
And also tried:
convoNet.add(Conv2D(10, (29, 3), 1, input_shape=(maxRow, 29, 1)))
With this error:
Traceback (most recent call last):
File "/Users/bl755p/Documents/WRT_NLP.py", line 645, in <module>
convoNet.add(Conv2D(10, (29, 3), 1, input_shape=(maxRow, 29, 1)))
File "/Users/bl755p/anaconda/envs/ATT_NLP-TensorFlow/lib/python3.5/site-packages/keras/models.py", line 299, in add
layer.create_input_layer(batch_input_shape, input_dtype)
File "/Users/bl755p/anaconda/envs/ATT_NLP-TensorFlow/lib/python3.5/site-packages/keras/engine/topology.py", line 401, in create_input_layer
self(x)
File "/Users/bl755p/anaconda/envs/ATT_NLP-TensorFlow/lib/python3.5/site-packages/keras/engine/topology.py", line 546, in __call__
self.build(input_shapes[0])
File "/Users/bl755p/anaconda/envs/ATT_NLP-TensorFlow/lib/python3.5/site-packages/keras/layers/convolutional.py", line 436, in build
constraint=self.W_constraint)
File "/Users/bl755p/anaconda/envs/ATT_NLP-TensorFlow/lib/python3.5/site-packages/keras/engine/topology.py", line 418, in add_weight
weight = initializer(shape, name=name)
File "/Users/bl755p/anaconda/envs/ATT_NLP-TensorFlow/lib/python3.5/site-packages/keras/initializations.py", line 65, in glorot_uniform
s = np.sqrt(6. / (fan_in + fan_out))
TypeError: unsupported operand type(s) for /: 'float' and ‘tuple'
And tried this:
convoNet.add(Conv2D(10, (29, 3), (1,1), input_shape=(1, maxRow, 29)))
With this error:
Traceback (most recent call last):
File "/Users/bl755p/Documents/WRT_NLP.py", line 645, in <module>
convoNet.add(Conv2D(10, (29, 3), (1,1), input_shape=(1, maxRow, 29)))
File "/Users/bl755p/anaconda/envs/ATT_NLP-TensorFlow/lib/python3.5/site-packages/keras/models.py", line 299, in add
layer.create_input_layer(batch_input_shape, input_dtype)
File "/Users/bl755p/anaconda/envs/ATT_NLP-TensorFlow/lib/python3.5/site-packages/keras/engine/topology.py", line 401, in create_input_layer
self(x)
File "/Users/bl755p/anaconda/envs/ATT_NLP-TensorFlow/lib/python3.5/site-packages/keras/engine/topology.py", line 546, in __call__
self.build(input_shapes[0])
File "/Users/bl755p/anaconda/envs/ATT_NLP-TensorFlow/lib/python3.5/site-packages/keras/layers/convolutional.py", line 436, in build
constraint=self.W_constraint)
File "/Users/bl755p/anaconda/envs/ATT_NLP-TensorFlow/lib/python3.5/site-packages/keras/engine/topology.py", line 418, in add_weight
weight = initializer(shape, name=name)
File "/Users/bl755p/anaconda/envs/ATT_NLP-TensorFlow/lib/python3.5/site-packages/keras/initializations.py", line 66, in glorot_uniform
return uniform(shape, s, name=name)
File "/Users/bl755p/anaconda/envs/ATT_NLP-TensorFlow/lib/python3.5/site-packages/keras/initializations.py", line 33, in uniform
return K.random_uniform_variable(shape, -scale, scale, name=name)
File "/Users/bl755p/anaconda/envs/ATT_NLP-TensorFlow/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 616, in random_uniform_variable
shape = tuple(map(int, shape))
TypeError: int() argument must be a string, a bytes-like object or a number, not ‘tuple'
Tried this:
convoNet = Sequential()
convoNet.add(Input(shape=(None, maxRow, 29, 1)))
convoNet.add(Conv2D(10, (29, 3)))
convoNet.add(MaxPooling2D(pool_size=(2, 2)))
convoNet.add(Dropout(.5))
convoNet.add(Dense(2, activation='softmax'))
Error:
Traceback (most recent call last):
File "/Users/bl755p/Documents/WRT_NLP.py", line 645, in <module>
convoNet.add(Input(shape=(None, maxRow, 29, 1)))
File "/Users/bl755p/anaconda/envs/ATT_NLP-TensorFlow/lib/python3.5/site-packages/keras/models.py", line 284, in add
'Found: ' + str(layer))
TypeError: The added layer must be an instance of class Layer. Found: Tensor("input_1:0", shape=(?, ?, 23, 29, 1), dtype=float32)
I've also tried the other way you can configure your net:
convoNet = Sequential([
Conv2D(10, (29, 3), input_shape=(None, maxRow, 29, 1)),
MaxPooling2D(pool_size=(2, 2)),
Dropout(.5),
Dense(2, activation='softmax')
])
With the same results.
These are among the ***MULTITUDE*** of different things I’ve tried to get this to compile/run correctly over the last 2-3 hours, and nothing in their API helps since I seem to be doing everything they say to do nor does anything I can find online so I am at a loss. What am I missing here?