ValueError: Targets should be binary (0 or 1).
See original GitHub issueI am facing this issue.
ValueError: For binary cases, y must be comprised of 0's and 1's.
The task is multilabel, and I am converting to binary with:
def custom_prepare_batch(batch, device, non_blocking):
x, y = batch["img"], batch["lab"]
return (
convert_tensor(x, device=device, non_blocking=non_blocking),
convert_tensor(y, device=device, non_blocking=non_blocking),
)
### model update function
def process_function(engine, batch):
model.train()
images, targets = custom_prepare_batch(batch, device=device, non_blocking=True)
optimizer.zero_grad()
outputs = model(images)
for task in range(targets.shape[1]):
task_output = outputs[:,task]
task_target = targets[:,task]
mask = ~torch.isnan(task_target)
task_output = task_output[mask]
task_target = task_target[mask]
if len(task_target) > 0:
if agreement_threshold > 0.0:
mean_loss, masks = and_mask_utils.get_grads(
agreement_threshold=agreement_threshold,
batch_size=1,
loss_fn=criterion,
n_agreement_envs=batch_size,
params=optimizer.param_groups[0]['params'],
output=task_output,
target=task_target,
method="and_mask",
scale_grad_inverse_sparsity=scale_grad_inverse_sparsity,
)
else:
mean_loss = criterion(y_pred, y)
mean_loss.backward()
optimizer.step()
return {
# "batchloss": mean_loss.item()
}
I used this from the ignite docs:
def activated_output_transform(output):
y_pred, y = output
y_pred = torch.sigmoid(y_pred)
return y_pred, y
metrics = {
"roc_auc": ROC_AUC(activated_output_transform),
}
And, now I am getting
ValueError: Targets should be binary (0 or 1).
Issue Analytics
- State:
- Created 3 years ago
- Comments:16
Top Results From Across the Web
Accuracy Score ValueError: Can't Handle mix of binary and ...
I have a problem to evaluate the predicted results using the accuracy_score metric. This is my true Data : array([1, 1, 0, 0,...
Read more >classification metrics can't handle a mix of unknown and ...
ValueError : Classification metrics can't handle a mix of unknown and binary targets. You are trying to compare integer and non-integer values. (1...
Read more >ValueError while running multi-class predictions - nlp
I am doing multi-class predicition with softmax and CrossEntropyLoss. My output is [0.4559, 0.2230, 0.3211] and label is [1].
Read more >sklearn.preprocessing.LabelBinarizer
... 0, 0, 1]]). Binary targets transform to a column vector ... The 2-d matrix should only contain 0 and 1, represents multilabel...
Read more >Accuracy Score ValueError: Can't Handle mix of ... - Intellipaat
Accuracy Score ValueError: Can't Handle mix of binary and continuous target · array([1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you so much. This is exactly what my task looks like, and I can work with this.
Right, in this case, you have to split the target with
output_transform
function and create 16 metrics. Maybe, something like that could work in your case:HTH