<p dir="auto"><strong>Important note:</strong> the development of Keras is currently taking place at <a href="https://github.com/tensorflow/tensorflow"><code class="notranslate">github.com/tensorflow/tensorflow</code></a>. Please file your bug report by creating a new issue in the TensorFlow repository.</p>
<p dir="auto">Please note that multi-backend Keras development has been discontinued. Do not report issues about multi-backend Keras (Keras 2.3.1 and lower), only report issues about the TensorFlow implementation of Keras (tf.keras).<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/22041656/93724388-6ac34800-fb5b-11ea-8435-ff2489526a33.png"><img width="1535" alt="Screen Shot 2020-09-20 at 3 53 01 PM" src="https://user-images.githubusercontent.com/22041656/93724388-6ac34800-fb5b-11ea-8435-ff2489526a33.png" style="max-width: 100%;"></a></p>
<p dir="auto">How can I convert (None, 224,224,1) to (None,224,224,3) shape?</p>
<p dir="auto">I train a Keras model and want to perform some matrix operation on the output (e.g. numpy.matmul()). However, each time I try to use any of numpy functions (like, matmul(), dot(), concatenate()), the IPython kernel dies and restarts. I'm using Spyder IDE on Mac OS X, both Keras, Tensorflow, and numpy are up-to-date.<br>
Please help me identify the culprit!</p>
<p dir="auto">Additional details:</p>
<ul dir="auto">
<li>The problem occurs even if I use numpy functions with newly generated data, instead of the model outputs (see script below)</li>
<li>Numpy functions do not raise any errors if used before the model training</li>
<li>Using tensorflow.matmul instead of numpy.matmul helps to avoid the problem, but it is not a solution as in the end I need to use more than one numpy function</li>
</ul>
<p dir="auto">Here's the script I'm running:<br>
<code class="notranslate">from keras.layers import Input, Dense, Conv2D, MaxPooling2D,Flatten</code><br>
<code class="notranslate">from keras.models import Model</code><br>
<code class="notranslate">import numpy as np</code><br>
<code class="notranslate">import tensorflow as tf</code><br>
<code class="notranslate">import keras.utils as kutils</code><br>
<code class="notranslate">n_y = 10</code><br>
<code class="notranslate">mnist = tf.keras.datasets.mnist</code><br>
<code class="notranslate">(X_train, y_train), (X_test, y_test) = mnist.load_data()</code><br>
<code class="notranslate">y_train = kutils.to_categorical(y_train, n_y)</code><br>
<code class="notranslate">y_test = kutils.to_categorical(y_test, n_y)</code><br>
<code class="notranslate">X_train = X_train.reshape(X_train.shape[0], 28, 28,1)</code><br>
<code class="notranslate">X_test = X_test.reshape(X_test.shape[0], 28, 28,1)</code><br>
<code class="notranslate">channels = 512</code><br>
<code class="notranslate">X = Input(shape=(28,28,1)) # size of MNIST images</code><br>
<code class="notranslate">y = Input(shape=(n_y,))</code><br>
<code class="notranslate">conv1 = Conv2D(32, (3, 3), activation='relu')(X)</code><br>
<code class="notranslate">pool1 = MaxPooling2D((2, 2), strides=(2, 2), name='block1_pool')(conv1)</code><br>
<code class="notranslate">flatten = Flatten()(pool1)</code><br>
<code class="notranslate">h_1 = Dense(64, activation='relu')(flatten)</code><br>
<code class="notranslate">h_2 = Dense(10, activation='softmax')(h_1)</code><br>
<code class="notranslate">model = Model(inputs=[X,y], outputs=h_2)</code><br>
<code class="notranslate">model.summary()</code><br>
<code class="notranslate">model.compile(loss='mean_squared_error', optimizer='adam',metrics=['accuracy'])</code><br>
<code class="notranslate">model.fit([X_train, y_train],y_train, batch_size=channels, epochs=1, validation_split=0.1)</code><br>
<code class="notranslate">np.matmul(np.array([[1, 0],[0, 1]],dtype=np.float64),np.array([[2, 3],[4, 6]],dtype=np.float64))</code></p>