Category : keras

The following code works without the attention thing, however when I add it as seen below I get the following error: 61 62 decoder1 = layers.Reshape(target_shape=(4,512))(decoder1) —> 63 attention = layers.Attention()([encoder,decoder1])(decoder1) 64 attention = layers.Concatenate()([encoder, decoder1])(attention) 65 TypeError: ‘KerasTensor’ object is not callable The code: encoder = layers.Reshape(target_shape=(4,512))(encoder) decoder1 = layers.LSTM(2048)(encoder) decoder1 = layers.Reshape(target_shape=(4,512))(decoder1) attention ..

Read more

I have a multidimensional input (None, 8, 105) I need to access the value – i[-1:][0][-1:][0][:1] and make comparisons between y_py_actual, y_predicted and input_tensor This is more or less what I got, but the function doesn’t work def custon_loss(self, input_tensor): def loss(y_actual, y_predicted): i = input_tensor[0][-1:][0][:1] mse = K.mean(K.sum(K.square(y_actual – y_predicted))) return K.switch((K.greater(i, y_predicted) & ..

Read more

I want to do SGD linear regression with tf.GradientTape() for the following data: from sklearn.datasets import make_regression from sklearn.linear_model import LinearRegression np.random.seed(42) x, y = make_regression(1000, 1, bias=10.0, noise=30.0) y = y/y.std() plt.scatter(x, y) lr = LinearRegression() lr.fit(x, y) a, b = lr.coef_[0], lr.intercept_ print("Bias:", b, "Coef:", a) y_true = b + a * x ..

Read more