tf.keras

TypeError: __init__() got an unexpected keyword argument 'name' when loading a model with Custom Layer

TypeError: __init__() got an unexpected keyword argument 'name' when loading a model with Custom Layer Question: I made a custom layer in keras for reshaping the outputs of a CNN before feeding to ConvLSTM2D layer class TemporalReshape(Layer): def __init__(self,batch_size,num_patches): super(TemporalReshape,self).__init__() self.batch_size = batch_size self.num_patches = num_patches def call(self,inputs): nshape = (self.batch_size,self.num_patches)+inputs.shape[1:] return tf.reshape(inputs, nshape) def …

Total answers: 2

How to join an encoder and a decoder

How to join an encoder and a decoder Question: I have built the following encoder-decoder architecture, and the encoder and decoder both work fine separately: from tensorflow.keras.layers import LSTM, Input, Reshape, Lambda from tensorflow.keras.models import Model from tensorflow.keras import backend as K WORD_TO_INDEX = {"foo": 0, "bar": 1} MAX_QUERY_WORD_COUNT = 10 QUERY_ENCODING_SIZE = 15 # …

Total answers: 4

Keras – Validation Loss and Accuracy stuck at 0

Keras – Validation Loss and Accuracy stuck at 0 Question: I am trying to train a simple 2 layer Fully Connected neural net for Binary Classification in Tensorflow keras. I have split my data into Training and Validation sets with a 80-20 split using sklearn’s train_test_split(). When I call model.fit(X_train, y_train, validation_data=[X_val, y_val]), it shows …

Total answers: 2

How can I ignore or remove ".ipynb_checkpoints" in colab?

How can I ignore or remove ".ipynb_checkpoints" in colab? Question: My code in tf.keras is given below. I want to retrieve a file(Xscale.npy) in each sub_directory(component_0, component_1) of model_cnn folder. root_dir = ‘/content/drive/My Drive/DeepCID/model_cnn’ i=0 for (root, dirs, files) in os.walk(root_dir): for d in dirs: print(dirs) os.chdir(os.path.join(root, d)) print(os.getcwd()) datafile3 = ‘./Xscale.npy’ Xscale = np.load(datafile3) …

Total answers: 4

WARNING:tensorflow:sample_weight modes were coerced from … to ['…']

WARNING:tensorflow:sample_weight modes were coerced from … to ['…'] Question: Training an image classifier using .fit_generator() or .fit() and passing a dictionary to class_weight= as an argument. I never got errors in TF1.x but in 2.1 I get the following output when starting training: WARNING:tensorflow:sample_weight modes were coerced from … to [‘…’] What does it mean …

Total answers: 4

Passing `training=true` when using Tensorflow 2's Keras Functional API

Passing `training=true` when using Tensorflow 2's Keras Functional API Question: When operating in graph mode in TF1, I believe I needed to wire up training=True and training=False via feeddicts when I was using the functional-style API. What is the proper way to do this in TF2? I believe this is automatically handled when using tf.keras.Sequential. …

Total answers: 3

Tensorflow.Keras: Custom Constraint Not Working

Tensorflow.Keras: Custom Constraint Not Working Question: Im trying to implement the Weights Orthogonality Constraint showed here, in section 2.0. when i try to use it on a Keras Dense Layer, An Value Error is raised. This is happening too when trying to implement the Custom Uncorrelated Features Constraint in the part 3.0 of the same …

Total answers: 3

How to fix "AttributeError: module 'tensorflow' has no attribute 'get_default_graph'"?

How to fix "AttributeError: module 'tensorflow' has no attribute 'get_default_graph'"? Question: I am trying to run some code to create an LSTM model but i get an error: AttributeError: module ‘tensorflow’ has no attribute ‘get_default_graph’ My code is as follows: from keras.models import Sequential model = Sequential() model.add(Dense(32, input_dim=784)) model.add(Activation(‘relu’)) model.add(LSTM(17)) model.add(Dense(1, activation=’sigmoid’)) model.compile(loss=’binary_crossentropy’, optimizer=’adam’, …

Total answers: 19