xuebinqin / U-2-Net

The code for our newly accepted paper in Pattern Recognition 2020: "U^2-Net: Going Deeper with Nested U-Structure for Salient Object Detection."
Apache License 2.0
8.52k stars 1.47k forks source link

index error #48

Closed johnyquest7 closed 4 years ago

johnyquest7 commented 4 years ago

I tried to train on my image set. But got the following error. My folder setup train_images - has 2 folders - 'images ' and another folder 'mask' When I ran the script it showed the correct number of images, but then got the following error

Traceback (most recent call last): File "u2net_train.py", line 143, in loss2, loss = muti_bce_loss_fusion(d0, d1, d2, d3, d4, d5, d6, labels_v) File "u2net_train.py", line 42, in muti_bce_loss_fusion print("l0: %3f, l1: %3f, l2: %3f, l3: %3f, l4: %3f, l5: %3f, l6: %3f\n"%(loss0.data[0],loss1.data[0],loss2.data[0],loss3.data[0],loss4.data[0],loss5.data[0],loss6.data[0])) IndexError: invalid index of a 0-dim tensor. Use tensor.item() in Python or tensor.item<T>() in C++ to convert a 0-dim tensor to a number

johnyquest7 commented 4 years ago

This happened when I used u2netp

xuebinqin commented 4 years ago

It seems the issue of the different version of pytorch. Please make sure you are using pytorch 0.4.0 or you can change “loss0.data[0]” to fit your exact version of Pytorch.

On Jul 16, 2020, at 10:26 PM, Johnson Thomas notifications@github.com wrote:

I tried to train on my image set. But got the following error. My folder setup train_images - has 2 folders - 'images ' and another folder 'mask' When I ran the script it showed the correct number of images, but then got the following error

Traceback (most recent call last): File "u2net_train.py", line 143, in loss2, loss = muti_bce_loss_fusion(d0, d1, d2, d3, d4, d5, d6, labels_v) File "u2net_train.py", line 42, in muti_bce_loss_fusion print("l0: %3f, l1: %3f, l2: %3f, l3: %3f, l4: %3f, l5: %3f, l6: %3f\n"%(loss0.data[0],loss1.data[0],loss2.data[0],loss3.data[0],loss4.data[0],loss5.data[0],loss6.data[0])) IndexError: invalid index of a 0-dim tensor. Use tensor.item() in Python or tensor.item() in C++ to convert a 0-dim tensor to a number

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/NathanUA/U-2-Net/issues/48, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSGORJQKFXMRUEOGMLFPA3R37HF5ANCNFSM4O5PSVCA.

johnyquest7 commented 4 years ago

thanks, I am using pytorch 1.5