Hi all,
I want to use trainable wieghts for the classes in a 5 dimentional tensor (batch size, 60,36,60, 12), the last chanel for sematic labels, the 60,36,60 is one hot coding. I need to add weights for the ones only in the volume 60,36,60. How can I do it in the fit_generator? I am using tensorflow 1.9
To add trainable weights for the classes in your 5-dimensional tensor, specifically for the ones in the 60x36x60 volume, you can use a custom layer or modify your model architecture.
Here a attached gist for your reference , kindly use the updated version of TF that is 2.17 for better functionality and features .
To add trainable weights for the classes in your 5-dimensional tensor using TensorFlow 1.9, you can create a custom loss function that incorporates these weights. First, define a trainable variable with shape (60, 36, 60) using tf.Variable(). In your model definition, apply this weight tensor to the relevant part of your input tensor using element-wise multiplication. Then, in your custom loss function, use these weighted values when calculating the loss. To use this in fit_generator(), pass your custom loss function as the loss parameter. You may need to adjust your model architecture slightly to accommodate these weights. Remember to update your optimizer to include the new trainable weights. If you need more specific guidance, please provide details about your current model architecture and loss function.