Category : tf.keras

import numpy as np import tensorflow as tf class ProbDistWRTChoices(tf.keras.layers.Layer): def __init__(self, maxChoice): super().__init__() self.maxChoice = maxChoice def call(self, inputs): utility, rowlengths = inputs utility = tf.reshape(utility, -1) utility = tf.RaggedTensor.from_row_lengths(values = utility, row_lengths = rowlengths) utility = utility.to_tensor(default_value = -1e9, shape = (None, self.maxChoice)) prob = tf.nn.softmax(utility, axis=-1) return prob class MNLogit(tf.keras.Model): def __init__(self, ..

Read more

I’m running an LSTM network that works fine (TF 2.0). My problem starts when trying to modify the loss function. I planed to adjust some data manipulation over ‘y_true’ and ‘y_pred’ but since TF force to maintain the data as tensors (and not convert it to Pandas or NumPy) it is challenging. To get better ..

Read more

I’m familiar with the confusion_matrix function from sklearn. But I have a large data-set where I train a model with. I created a data generator using keras functionality, flow_from_dataframe, it works fine and the model learns properly and also predicts. But I wish to do a confusion matrix of the performance but instead of having ..

Read more

Tensorflow 2.0 python 3.7 I trained and saved a model like this using tf.keras import tensorflow as tf from tensorflow import keras from tensorflow.keras import datasets, layers, models from tensorflow.keras.datasets import mnist (train_images, train_labels), (test_images, test_labels) = datasets.cifar10.load_data() # Normalize pixel values to be between 0 and 1 train_images, test_images = train_images / 255.0, test_images ..

Read more

I try to use a single optimizer to update both model’s parameters at the same time, however, I am having trouble setting this up. The overall idea is: (Assume model 1 and model 2 are sequential models) ”’ output1=model1(input1) imm1=normalized(output1)#over here, i normalized the output1 with numpy output2=model2(imm1) output3=concat(output2,ouput1) #numpy function loss1=l1norm(imm1-output3) #numpy function loss2=l2norm(imm1+output2,output3) ..

Read more