Skip to main content

All Questions

2 votes
1 answer
37 views

How do I update pixelClassificationLayer() to a custom loss function?

I have seen in the Mathworks official website for the pixelClassificationLayer() function that I should update it to a custom loss function using the following code: function loss = modelLoss(Y,T) ...
JAIME GOMEZ's user avatar
-1 votes
1 answer
54 views

How to track loss of multi-label MLP?

I am given binary data points of dimension 5,000. I am asked to perform machine learning predicting a binary vector of length 1k, where each position of the output is a class. The classes are not ...
Tim's user avatar
  • 53
1 vote
0 answers
378 views

Triplet Loss with Cross Entropy Loss?

I'm trying to learn how to use a TripletLoss in a Siamese Network. My goal is to build a classification siamese model, so I suppose I need both a Triplet Loss to minimize distances and a Cross Entropy ...
ChiG's user avatar
  • 19
1 vote
1 answer
90 views

Where are the actual predictions stored for Tensorflow keras CategoricalCrossentrophy model?

I'm learning about python and machine learning and reproduced some published code in a Kaggle notebook and modified it for my data within Azure Data Studio running Python 3. (Removed externally ...
joshAU's user avatar
  • 39
0 votes
1 answer
73 views

CrossEntropyLoss using weights gives RuntimeError: expected scalar type Float but found Long neural network

I am using a Feedforward neural network for a classification task with 4 classes. The classes are imbalanced and hence, I want to use a weight with the CrossEntropyLoss as mentioned here. Here is my ...
diviquery's user avatar
  • 759
0 votes
1 answer
282 views

Why does my MLP model's loss explode when using softmax and cross entropy in Python?

I am writing an NLP model from scratch in Python, using only NumPy for most of the functions. import numpy as np # my loss and activation functions def relu(x): return np.maximum(0, x) def ...
Capta1n_n9m0's user avatar
0 votes
1 answer
252 views

PyTorch CrossEntropyLoss documentation example crashes

To make sure I'm using PyTorch CrossEntropyLoss correctly, I'm trying the examples from the documentation: https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html However, the first ...
rwallace's user avatar
  • 33.7k
3 votes
0 answers
123 views

"RuntimeError: Expected target size" error for the nn.CrossEntropyLoss() function

I am trying to train a GPT-2 model to take in a tokenized/padded input and predict the output. My batch size is 32. My max length is 343. I believe that the 768 comes from the model. I cannot get the ...
C_Dog's user avatar
  • 31
0 votes
1 answer
925 views

What is the correct way to penalize one prediction more over another?

I have a BERT-based sequence classification model that takes as an input 4 strings and out 2 labels for each one: my_input = [string_1, string_2, string_3, string_4] out_logits = model(my_input)....
Penguin's user avatar
  • 2,581
2 votes
1 answer
1k views

Different cross entropy results from NumPy and PyTorch

My prediction is y_hat = [ 0.57,0.05,0.14,0.10,0.14] and target is target =[ 1, 0, 0, 0, 0 ]. I need to calculate Cross Entropy loss by NumPy and Pytorch loss function. Using NumPy my formula is -np....
hello m's user avatar
  • 21
1 vote
1 answer
328 views

difference in categorical crossentropy when specified in loss or metrics

What is the difference between tf.keras.losses.CategoricalCrossentropy and tf.keras.metrics.CategoricalCrossentropy? model.compile(optimizer=Adam(learning_rate=lr), loss= 'categorical_crossentropy', ...
Seena's user avatar
  • 131
-1 votes
1 answer
3k views

Is this formula of cross entropy for a single example i with C classes correctly written?

If y is the label and hat y is my prediction, would the following formula for cross-entropy with the number of C possible classes be right: In the case of a Binary Cross Entropy, can I just remove ...
user3352632's user avatar
0 votes
1 answer
166 views

Is it possible to use PyTorch's `BatchNorm1d` with `BCELossWithLogits`?

I am attempting to normalize the outputs of my classifier that uses BCELossWithLogits as part of its loss function. As far as I know, this implements Sigmoid function internally and outputs the loss. ...
fireking04's user avatar
-1 votes
1 answer
289 views

Is this formula for weighted binary cross entropy loss correct?

Here it is the formula I built: My equation for weighted binary cross entropy loss Where: alpha(i) = #Negative samples / Total samples if y(i)=1 alpha(i) = #Positive samples / Total samples if y(i)=0 ...
inginging's user avatar
1 vote
1 answer
340 views

Getting RESNet18 to work with float32 data [duplicate]

I have float32 data that I am trying to get RESNet18 to work with. I am using the RESNet model in torchvision (and using pytorch lightning) and modified it to use one layer (grayscale) data like so: ...
DLH's user avatar
  • 199

15 30 50 per page
1
2 3 4 5
X