ValueError:The requested array has an inhomogeneous shape after 2 dimensions.The detected shape was(318, 20)+inhomogeneous part - machine-learning

from sklearn.neural_network import MLPClassifier
#Initialise Multi Layer Perceptron Classifier (MLP)
model = MLPClassifier(alpha = 0.01, batch_size = 256, epsilon = 1e-08, hidden_layer_sizes = (400,), learning_rate = 'adaptive', max_iter = 500)
model.fit(X_train, y_train)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-41-d768f88d541e> in <module>
----> 1 model.fit(X_train, y_train)
5 frames
/usr/local/lib/python3.8/dist-packages/sklearn/neural_network/_multilayer_perceptron.py in fit(self, X, y)
750 Returns a trained MLP model.
751 """
--> 752 return self._fit(X, y, incremental=False)
753
754 def _check_solver(self):
/usr/local/lib/python3.8/dist-packages/sklearn/neural_network/_multilayer_perceptron.py in _fit(self, X, y, incremental)
391 )
392
--> 393 X, y = self._validate_input(X, y, incremental, reset=first_pass)
394
395 n_samples, n_features = X.shape
/usr/local/lib/python3.8/dist-packages/sklearn/neural_network/_multilayer_perceptron.py in _validate_input(self, X, y, incremental, reset)
1098
1099 def _validate_input(self, X, y, incremental, reset):
-> 1100 X, y = self._validate_data(
1101 X,
1102 y,
/usr/local/lib/python3.8/dist-packages/sklearn/base.py in _validate_data(self, X, y, reset, validate_separately, **check_params)
579 y = check_array(y, **check_y_params)
580 else:
--> 581 X, y = check_X_y(X, y, **check_params)
582 out = X, y
583
/usr/local/lib/python3.8/dist-packages/sklearn/utils/validation.py in check_X_y(X, y, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, estimator)
962 raise ValueError("y cannot be None")
963
--> 964 X = check_array(
965 X,
966 accept_sparse=accept_sparse,
/usr/local/lib/python3.8/dist-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator)
744 array = array.astype(dtype, casting="unsafe", copy=False)
745 else:
--> 746 array = np.asarray(array, order=order, dtype=dtype)
747 except ComplexWarning as complex_warning:
748 raise ValueError(
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (318, 20) + inhomogeneous part.
for i in X_train:
print(i.shape)
(20, 100)
(20, 80)
(20, 69)
(20, 60)
(20, 67)
(20, 60)
(20, 60)
(20, 69)
(20, 63)
(20, 60)
(20, 92)
(20, 70)
(20, 63)
(20, 79)
(20, 53)
(20, 81)
(20, 86)
(20, 69)
(20, 87)
(20, 79)
(20, 76)
(20, 58)
(20, 84)
(20, 89)
(20, 90)
(20, 94)
(20, 117)
(20, 57)
(20, 83)
(20, 63)
(20, 81)
(20, 76)
(20, 84)
(20, 80)
(20, 73)
(20, 120)
(20, 79)
(20, 73)
(20, 81)
(20, 84)
(20, 81)
(20, 86)
(20, 74)
(20, 92)
(20, 84)
(20, 104)
(20, 73)
(20, 54)
(20, 81)
(20, 84)
(20, 76)
(20, 81)
(20, 107)
(20, 109)
(20, 107)
(20, 86)
(20, 94)
(20, 80)
(20, 73)
(20, 69)
(20, 107)
(20, 67)
(20, 79)
(20, 76)
(20, 70)
(20, 56)
(20, 70)
(20, 66)
(20, 71)
(20, 83)
(20, 74)
(20, 64)
(20, 76)
(20, 94)
(20, 69)
(20, 71)
(20, 103)
(20, 80)
(20, 97)
(20, 83)
(20, 79)
(20, 70)
(20, 70)
(20, 99)
(20, 90)
(20, 67)
(20, 64)
(20, 73)
(20, 87)
(20, 71)
(20, 84)
(20, 69)
(20, 84)
(20, 66)
(20, 92)
(20, 90)
(20, 67)
(20, 104)
(20, 71)
(20, 63)
(20, 96)
(20, 79)
(20, 84)
(20, 104)
(20, 54)
(20, 97)
(20, 81)
(20, 61)
(20, 79)
(20, 81)
(20, 79)
(20, 93)
(20, 102)
(20, 107)
(20, 76)
(20, 106)
(20, 94)
(20, 79)
(20, 99)
(20, 66)
(20, 100)
(20, 70)
(20, 83)
(20, 87)
(20, 93)
(20, 76)
(20, 77)
(20, 76)
(20, 73)
(20, 66)
(20, 107)
(20, 71)
(20, 79)
(20, 699)
(20, 57)
(20, 57)
(20, 70)
(20, 107)
(20, 84)
(20, 71)
(20, 71)
(20, 99)
(20, 67)
(20, 77)
(20, 92)
(20, 81)
(20, 76)
(20, 54)
(20, 77)
(20, 63)
(20, 64)
(20, 83)
(20, 66)
(20, 64)
(20, 110)
(20, 81)
(20, 74)
(20, 64)
(20, 76)
(20, 71)
(20, 71)
(20, 87)
(20, 146)
(20, 96)
(20, 97)
(20, 103)
(20, 70)
(20, 60)
(20, 61)
(20, 77)
(20, 70)
(20, 104)
(20, 83)
(20, 96)
(20, 53)
(20, 86)
(20, 64)
(20, 90)
(20, 92)
(20, 64)
(20, 84)
(20, 69)
(20, 63)
(20, 69)
(20, 46)
(20, 50)
(20, 56)
(20, 60)
(20, 100)
(20, 50)
(20, 51)
(20, 96)
(20, 92)
(20, 87)
(20, 84)
(20, 63)
(20, 64)
(20, 90)
(20, 71)
(20, 54)
(20, 126)
(20, 80)
(20, 79)
(20, 63)
(20, 89)
(20, 94)
(20, 77)
(20, 87)
(20, 69)
(20, 67)
(20, 90)
(20, 84)
(20, 117)
(20, 77)
(20, 70)
(20, 80)
(20, 90)
(20, 81)
(20, 81)
(20, 64)
(20, 79)
(20, 56)
(20, 60)
(20, 79)
(20, 73)
(20, 58)
(20, 67)
(20, 89)
(20, 80)
(20, 57)
(20, 96)
(20, 83)
(20, 70)
(20, 81)
(20, 69)
(20, 83)
(20, 80)
(20, 58)
(20, 93)
(20, 64)
(20, 63)
(20, 60)
(20, 64)
(20, 92)
(20, 63)
(20, 80)
(20, 106)
(20, 93)
(20, 63)
(20, 80)
(20, 96)
(20, 90)
(20, 112)
(20, 80)
(20, 90)
(20, 94)
(20, 86)
(20, 94)
(20, 79)
(20, 80)
(20, 76)
(20, 47)
(20, 60)
(20, 76)
(20, 90)
(20, 70)
(20, 96)
(20, 142)
(20, 92)
(20, 89)
(20, 84)
(20, 69)
(20, 71)
(20, 81)
(20, 106)
(20, 63)
(20, 80)
(20, 69)
(20, 86)
(20, 92)
(20, 69)
(20, 83)
(20, 80)
(20, 57)
(20, 61)
(20, 67)
(20, 97)
(20, 94)
(20, 94)
(20, 54)
(20, 76)
(20, 89)
(20, 70)
(20, 79)
(20, 69)
(20, 67)
(20, 53)
(20, 90)
(20, 81)
(20, 94)
(20, 100)
(20, 90)
(20, 70)
(20, 70)
(20, 71)
(20, 83)
(20, 70)
(20, 84)
(20, 86)
(20, 66)
(20, 87)
(20, 70)
(20, 63)
(20, 69)
(20, 94)
(20, 58)
(20, 92)
(20, 83)
need help to solve this error

In MLP, the input size of all the samples must be the same. But in your case, the sample sizes are different which is not permitted. So you can do two things:
Either truncate all the samples so that each sample has the size of the smallest sample.
Zero-pad each sample so that each sample has the size of the largest sample.

Related

Keras Dense Model ValueError: logits and labels must have the same shape ((None, 200, 1) vs (None, 1, 1))

I'm new in machine learning and I'm trying to train a model.
I'm using this Keras oficial example as a guide to set my dataset and feed it into the model: https://www.tensorflow.org/api_docs/python/tf/keras/utils/Sequence
From the training data I have an sliding windows created for a single column and for the labels I have a binary classification (1 or 0).
This is the model creation code:
n = 200
hidden_units = n
dense_model = Sequential()
dense_model.add(Dense(hidden_units, input_shape=([200,1])))
dense_model.add(Activation('relu'))
dense_model.add(Dropout(dropout))
print(hidden_units)
while hidden_units > 2:
hidden_units = math.ceil(hidden_units/2)
dense_model.add(Dense(hidden_units))
dense_model.add(Activation('relu'))
dense_model.add(Dropout(dropout))
print(hidden_units)
dense_model.add(Dense(units = 1, activation='sigmoid'))
This is the functions I'm using to compile the model:
def compile_and_fit(model, window, epochs, patience=2):
early_stopping = tf.keras.callbacks.EarlyStopping(monitor='val_loss',
patience=patience,
mode='min')
model.compile(loss='binary_crossentropy',
optimizer='adam',
metrics=['accuracy'])
model.fit(window.train , epochs=epochs)
return history
This is the model training:
break_batchs = find_gaps(df_train, 'date_diff', diff_int_value)
for keys, values in break_batchs.items():
dense_window = WindowGenerator(data=df_train['price_var'],
data_validation=df_validation['price_var'],
data_test=df_test['price_var'],
input_width=n,
shift=m,
start_index=values[0],
end_index=values[1],
class_labels=y_buy,
class_labels_train=y_buy_train,
class_labels_test=y_buy_test,
label_width=1,
label_columns=None,
classification=True,
batch_size=batch_size,
seed=None)
history = compile_and_fit(dense_model, dense_window)
and those are the shapes of the batches:
(TensorSpec(shape=(None, 200, 1), dtype=tf.float32, name=None), TensorSpec(shape=(None, 1, 1), dtype=tf.float64, name=None))
The problem is (I guess) that, from the model summary the model is training from the last dimension when it should be working in the second one:
dense_model.summary()
Model: "sequential_21"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
|Model is being applied here
|
v
dense_232 (Dense) (None, 200, 200) 400
_________________________________________________________________
|When it should be applied here
|
v
activation_225 (Activation) (None, 200, 200) 0
_________________________________________________________________
dropout_211 (Dropout) (None, 200, 200) 0
_________________________________________________________________
dense_233 (Dense) (None, 200, 100) 20100
_________________________________________________________________
activation_226 (Activation) (None, 200, 100) 0
_________________________________________________________________
dropout_212 (Dropout) (None, 200, 100) 0
_________________________________________________________________
dense_234 (Dense) (None, 200, 50) 5050
_________________________________________________________________
activation_227 (Activation) (None, 200, 50) 0
_________________________________________________________________
dropout_213 (Dropout) (None, 200, 50) 0
_________________________________________________________________
dense_235 (Dense) (None, 200, 25) 1275
_________________________________________________________________
activation_228 (Activation) (None, 200, 25) 0
_________________________________________________________________
dropout_214 (Dropout) (None, 200, 25) 0
_________________________________________________________________
dense_236 (Dense) (None, 200, 13) 338
_________________________________________________________________
activation_229 (Activation) (None, 200, 13) 0
_________________________________________________________________
dropout_215 (Dropout) (None, 200, 13) 0
_________________________________________________________________
dense_237 (Dense) (None, 200, 7) 98
_________________________________________________________________
activation_230 (Activation) (None, 200, 7) 0
_________________________________________________________________
dropout_216 (Dropout) (None, 200, 7) 0
_________________________________________________________________
dense_238 (Dense) (None, 200, 4) 32
_________________________________________________________________
activation_231 (Activation) (None, 200, 4) 0
_________________________________________________________________
dropout_217 (Dropout) (None, 200, 4) 0
_________________________________________________________________
dense_239 (Dense) (None, 200, 2) 10
_________________________________________________________________
activation_232 (Activation) (None, 200, 2) 0
_________________________________________________________________
dropout_218 (Dropout) (None, 200, 2) 0
_________________________________________________________________
dense_240 (Dense) (None, 200, 1) 3
=================================================================
Total params: 27,306
Trainable params: 27,306
Non-trainable params: 0
_________________________________________________________________
And because of that Im getting ValueError: logits and labels must have the same shape ((None, 200, 1) vs (None, 1, 1))
How can I tell Keras to apply the training in the second dimension and not the last one?
EDIT
This is what I understand is happening, is this right? How I fixed it?
Edit 2
I tried to modify as suggested, using:
dense_model.add(Dense(hidden_units, input_shape=(None,200,1)))
but I'm getting the following warning:
WARNING:tensorflow:Model was constructed with shape (None, None, 200, 1) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, 200, 1), dtype=tf.float32, name='dense_315_input'), name='dense_315_input', description="created by layer 'dense_315_input'"), but it was called on an input with incompatible shape (None, 200, 1, 1).
The first dimension that you are pointing at is batch size, as you specified in your input layer (the input shape is [batch_size, input_dim] as can be seen here
dense_model.add(Dense(hidden_units, input_shape=([200,1])))
So your model is outputting 200 values because your batch size is 200, but the target label you are comparing only has one value.

darknet mask and anchor values for yolov4

In the README.md of darknet repo https://github.com/AlexeyAB/darknet we have this sentence about anchor boxes:
But you should change indexes of anchors masks= for each [yolo]-layer, so for YOLOv4 the 1st-[yolo]-layer has anchors smaller than 30x30, 2nd smaller than 60x60, 3rd remaining.
It looks like the default anchor boxes for yolov4-sam-mish.cfg are
12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401
and the first yolo layer has config:
mask = 0,1,2
Do I understand correctly that this will use those anchors?
(12, 16), (19, 36), (40, 28)
If yes it seems to contradict with the statement or do I understand it incorrectly.
I'm asking because for my dataset and my image sizes (256, 96) I got those anchors from calc_anchors in darknet
15, 56, 22, 52, 28, 48, 23, 62, 26, 59, 39, 43, 31, 57, 29, 66, 37, 64
and trying to figure out how should I set the masks.
Looks good to me.
12, 16,
19, 36,
40, 28,
36, 75,
76, 55,
72, 146,
142, 110,
192, 243,
459, 401
You may leave the masks as are. She current config you show will yield higher MaP; supporting documentation here:
https://github.com/WongKinYiu/PartialResidualNetworks/issues/2

Trained an convoluted autoencoder. Now need help extracting the feature space

I built an autoencoder using my own data set of about 32k images. I did a 75/25 split for training/testing, and I was able to get results I'm happy with.
Now I want to be able to extract the feature space and map them to every image in my dataset and to new data that wasn't tested. I couldn't find a tutorial online that delved into using the encoder as a feature space. All I could find was to build the full network.
My code:
> input_img = Input(shape=(200, 200, 1))
# encoder part of the model (increased filter lyaer after each filter)
x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(32, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(64, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(128, (3, 3), activation='relu', padding='same')(x)
encoded = MaxPooling2D((2, 2), padding='same')(x)
# decoder part of the model (went backwards from the encoder)
x = Conv2D(128, (3, 3), activation='relu', padding='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Conv2D(64, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
x = Conv2D(32, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
x = Conv2D(16, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
x = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)
decoded = Cropping2D(cropping=((8,0), (8,0)), data_format=None)(x)
autoencoder = Model(input_img, decoded)
autoencoder.compile(optimizer='adam', loss='binary_crossentropy')
autoencoder.summary()
Here's my net setup if anybody is interested:
Model: "model_22"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_23 (InputLayer) (None, 200, 200, 1) 0
_________________________________________________________________
conv2d_186 (Conv2D) (None, 200, 200, 16) 160
_________________________________________________________________
max_pooling2d_83 (MaxPooling (None, 100, 100, 16) 0
_________________________________________________________________
conv2d_187 (Conv2D) (None, 100, 100, 32) 4640
_________________________________________________________________
max_pooling2d_84 (MaxPooling (None, 50, 50, 32) 0
_________________________________________________________________
conv2d_188 (Conv2D) (None, 50, 50, 64) 18496
_________________________________________________________________
max_pooling2d_85 (MaxPooling (None, 25, 25, 64) 0
_________________________________________________________________
conv2d_189 (Conv2D) (None, 25, 25, 128) 73856
_________________________________________________________________
max_pooling2d_86 (MaxPooling (None, 13, 13, 128) 0
_________________________________________________________________
conv2d_190 (Conv2D) (None, 13, 13, 128) 147584
_________________________________________________________________
up_sampling2d_82 (UpSampling (None, 26, 26, 128) 0
_________________________________________________________________
conv2d_191 (Conv2D) (None, 26, 26, 64) 73792
_________________________________________________________________
up_sampling2d_83 (UpSampling (None, 52, 52, 64) 0
_________________________________________________________________
conv2d_192 (Conv2D) (None, 52, 52, 32) 18464
_________________________________________________________________
up_sampling2d_84 (UpSampling (None, 104, 104, 32) 0
_________________________________________________________________
conv2d_193 (Conv2D) (None, 104, 104, 16) 4624
_________________________________________________________________
up_sampling2d_85 (UpSampling (None, 208, 208, 16) 0
_________________________________________________________________
conv2d_194 (Conv2D) (None, 208, 208, 1) 145
_________________________________________________________________
cropping2d_2 (Cropping2D) (None, 200, 200, 1) 0
=================================================================
Total params: 341,761
Trainable params: 341,761
Non-trainable params: 0
Then my training:
autoencoder.fit(train, train,
epochs=3,
batch_size=128,
shuffle=True,
validation_data=(test, test))
My results:
Train on 23412 samples, validate on 7805 samples
Epoch 1/3
23412/23412 [==============================] - 773s 33ms/step - loss: 0.0620 - val_loss: 0.0398
Epoch 2/3
23412/23412 [==============================] - 715s 31ms/step - loss: 0.0349 - val_loss: 0.0349
Epoch 3/3
23412/23412 [==============================] - 753s 32ms/step - loss: 0.0314 - val_loss: 0.0319
Rather not share the images, but they look well reconstructed.
Thank you for all and any help!
Not sure if I fully understand your questions, but do you want to get the resulting feature space for every image you trained on as well as others. Why not just do this?
Name your encoded layer in your autoencoder architecture as 'embedding.' Then create the encoder the following way:
embedding_layer = autoencoder.get_layer(name='embedding').output
encoder = Model(input_img,embedding_layer)

How can I determine the input dimensions for a caffe blob

I'm trying to print out some diagnostics for a caffe net, but although I can find the shape of the data output by a blob, I cannot directly find the shape of the expected input data. For example:
nb = self.net.blobs # nb is an OrderedDict of the blob objects
that make up a VGG16 net
for ctr, name in enumerate(nb):
print ctr, name, nb[name].data.shape
0 data (10, 3, 224, 224)
1 conv1_1 (10, 64, 224, 224)
2 conv1_2 (10, 64, 224, 224)
3 pool1 (10, 64, 112, 112)
4 conv2_1 (10, 128, 112, 112)
5 conv2_2 (10, 128, 112, 112)
6 pool2 (10, 128, 56, 56)
7 conv3_1 (10, 256, 56, 56)
8 conv3_2 (10, 256, 56, 56)
9 conv3_3 (10, 256, 56, 56)
10 pool3 (10, 256, 28, 28)
11 conv4_1 (10, 512, 28, 28)
12 conv4_2 (10, 512, 28, 28)
13 conv4_3 (10, 512, 28, 28)
14 pool4 (10, 512, 14, 14)
15 conv5_1 (10, 512, 14, 14)
16 conv5_2 (10, 512, 14, 14)
17 conv5_3 (10, 512, 14, 14)
18 pool5 (10, 512, 7, 7)
19 fc6 (10, 4096)
20 fc7 (10, 4096)
21 fc8a (10, 365)
22 prob (10, 365)
How can I change this code so that the output is of the form:
layer_number layer_name input_shape output_shape
without directly querying the parent layer to see what output it gives?
You can modify the code in this answer to iterate the net layer by layer:
def dont_forget_to_thank_me_later(net):
for li in xrange(len(net.layers)): # for each layer in the net
print "{}\t{}\t".format(li, net._layer_names[li]),
# for each input to the layer (aka "bottom") print its name and shape
for bi in list(net._bottom_ids(li)):
print "{} ({}) ".format(net._blob_names[bi], net.blobs[net._blob_names[bi]].data.shape),
print "\t"
# for each output of the layer (aka "top") print its name and shape
for bi in list(net._top_ids(li)):
print "{} ({}) ".format(net._blob_names[bi], net.blobs[net._blob_names[bi]].data.shape)
print "" # end of line
Note that a layer may have more than one input, or more than one output...

Keras RuntimeError: GpuCorrMM failed to allocate working memory of 576 x 802816

I tryed to run a deep learning code in Keras but got following error message all the time. I've searched all around and spend much time but still failed to fix it up. I'm a fish, any help will be appreciated!!
runfile('E:/dilation-keras/predict.py', wdir='E:/dilation-keras')
Using Theano backend.
Using gpu device 0: GeForce GT 635M (CNMeM is enabled with initial size: 90.0% of memory, cuDNN not available)
____________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
====================================================================================================
input_3 (InputLayer) (None, 3, 900, 900) 0
____________________________________________________________________________________________________
conv1_1 (Convolution2D) (None, 64, 898, 898) 1792 input_3[0][0]
____________________________________________________________________________________________________
conv1_2 (Convolution2D) (None, 64, 896, 896) 36928 conv1_1[0][0]
____________________________________________________________________________________________________
pool1 (MaxPooling2D) (None, 64, 448, 448) 0 conv1_2[0][0]
____________________________________________________________________________________________________
conv2_1 (Convolution2D) (None, 128, 446, 446) 73856 pool1[0][0]
____________________________________________________________________________________________________
conv2_2 (Convolution2D) (None, 128, 444, 444) 147584 conv2_1[0][0]
____________________________________________________________________________________________________
pool2 (MaxPooling2D) (None, 128, 222, 222) 0 conv2_2[0][0]
____________________________________________________________________________________________________
conv3_1 (Convolution2D) (None, 256, 220, 220) 295168 pool2[0][0]
____________________________________________________________________________________________________
conv3_2 (Convolution2D) (None, 256, 218, 218) 590080 conv3_1[0][0]
____________________________________________________________________________________________________
conv3_3 (Convolution2D) (None, 256, 216, 216) 590080 conv3_2[0][0]
____________________________________________________________________________________________________
pool3 (MaxPooling2D) (None, 256, 108, 108) 0 conv3_3[0][0]
____________________________________________________________________________________________________
conv4_1 (Convolution2D) (None, 512, 106, 106) 1180160 pool3[0][0]
____________________________________________________________________________________________________
conv4_2 (Convolution2D) (None, 512, 104, 104) 2359808 conv4_1[0][0]
____________________________________________________________________________________________________
conv4_3 (Convolution2D) (None, 512, 102, 102) 2359808 conv4_2[0][0]
____________________________________________________________________________________________________
conv5_1 (AtrousConvolution2D) (None, 512, 98, 98) 2359808 conv4_3[0][0]
____________________________________________________________________________________________________
conv5_2 (AtrousConvolution2D) (None, 512, 94, 94) 2359808 conv5_1[0][0]
____________________________________________________________________________________________________
conv5_3 (AtrousConvolution2D) (None, 512, 90, 90) 2359808 conv5_2[0][0]
____________________________________________________________________________________________________
fc6 (AtrousConvolution2D) (None, 4096, 66, 66) 102764544 conv5_3[0][0]
____________________________________________________________________________________________________
drop6 (Dropout) (None, 4096, 66, 66) 0 fc6[0][0]
____________________________________________________________________________________________________
fc7 (Convolution2D) (None, 4096, 66, 66) 16781312 drop6[0][0]
____________________________________________________________________________________________________
drop7 (Dropout) (None, 4096, 66, 66) 0 fc7[0][0]
____________________________________________________________________________________________________
fc-final (Convolution2D) (None, 21, 66, 66) 86037 drop7[0][0]
____________________________________________________________________________________________________
zeropadding2d_3 (ZeroPadding2D) (None, 21, 132, 132) 0 fc-final[0][0]
____________________________________________________________________________________________________
ct_conv1_1 (Convolution2D) (None, 42, 130, 130) 7980 zeropadding2d_3[0][0]
____________________________________________________________________________________________________
ct_conv1_2 (Convolution2D) (None, 42, 128, 128) 15918 ct_conv1_1[0][0]
____________________________________________________________________________________________________
ct_conv2_1 (AtrousConvolution2D) (None, 84, 124, 124) 31836 ct_conv1_2[0][0]
____________________________________________________________________________________________________
ct_conv3_1 (AtrousConvolution2D) (None, 168, 116, 116) 127176 ct_conv2_1[0][0]
____________________________________________________________________________________________________
ct_conv4_1 (AtrousConvolution2D) (None, 336, 100, 100) 508368 ct_conv3_1[0][0]
____________________________________________________________________________________________________
ct_conv5_1 (AtrousConvolution2D) (None, 672, 68, 68) 2032800 ct_conv4_1[0][0]
____________________________________________________________________________________________________
ct_fc1 (Convolution2D) (None, 672, 66, 66) 4064928 ct_conv5_1[0][0]
____________________________________________________________________________________________________
ct_final (Convolution2D) (None, 21, 66, 66) 14133 ct_fc1[0][0]
____________________________________________________________________________________________________
permute_5 (Permute) (None, 66, 66, 21) 0 ct_final[0][0]
____________________________________________________________________________________________________
reshape_5 (Reshape) (None, 4356, 21) 0 permute_5[0][0]
____________________________________________________________________________________________________
activation_3 (Activation) (None, 4356, 21) 0 reshape_5[0][0]
____________________________________________________________________________________________________
reshape_6 (Reshape) (None, 66, 66, 21) 0 activation_3[0][0]
____________________________________________________________________________________________________
permute_6 (Permute) (None, 21, 66, 66) 0 reshape_6[0][0]
====================================================================================================
Total params: 141,149,720
Trainable params: 141,149,720
Non-trainable params: 0
____________________________________________________________________________________________________
batch_size is: 1
Traceback (most recent call last):
File "<ipython-input-3-641fac717a39>", line 1, in <module>
runfile('E:/dilation-keras/predict.py', wdir='E:/dilation-keras')
File "c:\users\lenovo\anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "c:\users\lenovo\anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "E:/dilation-keras/predict.py", line 74, in <module>
y_img = predict(im, model, ds)
File "E:/dilation-keras/predict.py", line 46, in predict
prob = model.predict(model_in,batch_size=batch_size)[0]
File "c:\users\lenovo\anaconda2\lib\site-packages\keras\engine\training.py", line 1272, in predict
batch_size=batch_size, verbose=verbose)
File "c:\users\lenovo\anaconda2\lib\site-packages\keras\engine\training.py", line 945, in _predict_loop
batch_outs = f(ins_batch)
File "c:\users\lenovo\anaconda2\lib\site-packages\keras\backend\theano_backend.py", line 959, in __call__
return self.function(*inputs)
File "c:\users\lenovo\anaconda2\lib\site-packages\theano\compile\function_module.py", line 886, in __call__
storage_map=getattr(self.fn, 'storage_map', None))
File "c:\users\lenovo\anaconda2\lib\site-packages\theano\gof\link.py", line 325, in raise_with_op
reraise(exc_type, exc_value, exc_trace)
File "c:\users\lenovo\anaconda2\lib\site-packages\theano\compile\function_module.py", line 873, in __call__
self.fn() if output_subset is None else\
RuntimeError: GpuCorrMM failed to allocate working memory of 576 x 802816
Apply node that caused the error: GpuCorrMM{valid, (1, 1), (1, 1)}(GpuContiguous.0, GpuContiguous.0)
Toposort index: 95
Inputs types: [CudaNdarrayType(float32, 4D), CudaNdarrayType(float32, 4D)]
Inputs shapes: [(1, 64, 898, 898), (64, 64, 3, 3)]
Inputs strides: [(0, 806404, 898, 1), (576, 9, 3, 1)]
Inputs values: ['not shown', 'not shown']
Outputs clients: [[GpuElemwise{Composite{(i0 * ((i1 + i2) + Abs((i1 + i2))))}}[(0, 1)](CudaNdarrayConstant{[[[[ 0.5]]]]}, GpuCorrMM{valid, (1, 1), (1, 1)}.0, GpuDimShuffle{x,0,x,x}.0)]]
HINT: Re-running with most Theano optimization disabled could give you a back-trace of when this node was created. This can be done with by setting the Theano flag 'optimizer=fast_compile'. If that does not work, Theano optimizations can be disabled with 'optimizer=None'.
HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.
The problem lies in memory. Your first ten conv2D layers need approximately 200MB each. This means that it's need 2GB for only storing output of your first 10 layers. This would surely not fit into your cards memory.

Resources