roboflow / notebooks

Examples and tutorials on using SOTA computer vision models and techniques. Learn everything from old-school ResNet, through YOLO and object-detection transformers like DETR, to the latest models like Grounding DINO and SAM.
https://roboflow.com/models
4.89k stars 759 forks source link

RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 13 but got size 0 for tensor number 1 in the list. #100

Closed rodoggyro closed 1 year ago

rodoggyro commented 1 year ago

Search before asking

Notebook name

This is the link to the notebook I am working in https://colab.research.google.com/drive/1nsZmuryO2lBz41CTTTBozO1VfQriXkll?usp=sharing.

Bug

When running the custom training code I ran into the error in the title. I also attached an image of the error. image_2023-04-20_103409355

Environment

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

github-actions[bot] commented 1 year ago

👋 Hello @rodoggyro, thank you for leaving an issue on Roboflow Notebooks.

🐞 Bug reports

If you are filing a bug report, please be as detailed as possible. This will help us more easily diagnose and resolve the problem you are facing. To learn more about contributing, check out our Contributing Guidelines.

If you require support with custom code that is not part of Roboflow Notebooks, please reach out on the Roboflow Forum or on the GitHub Discussions page associated with this repository.

💬 Get in touch

Do you have more questions about Roboflow that we haven't responded to yet? Feel free to ask them on the Roboflow Discuss forum. Our developer advocates and community team actively respond to questions there.

To ask questions about Notebooks, head over to the GitHub Discussions section of this repository.

mo-traor3-ai commented 1 year ago

@rodoggyro I just looked at your notebook and noticed you un-commented the cell that does the install of the ultralytics repo from GitHub, rather than only using the pip install in the cell above. Did you customize the ultralytics install, or your model architecture? That would be the only reason to clone the repo -- the pip install method above that is un-commented is the only one that needs to run, otherwise.

Try it again with this cell commented out, like in our original notebook:

**** Make sure you run this cell too, it wasn't run when you trained the model:

image image

^^ Can you try training with the above process and let us know if you still see a bug?

SkalskiP commented 1 year ago

I confirmed that the notebook does not work regardless if you install Ultralytics from pip or from the source.

I did more digging and this is what I found.

  1. I used this short script to asses if there are any label files that use a bounding box instead of the polygon.
import os

SOURCE_PATH = f"{HOME}/datasets/Car-Detection-Game-1/train/labels"

def read_lines_from_file(file_path):
    with open(file_path, 'r') as file:
        lines = file.readlines()
    return lines

for file_name in os.listdir(SOURCE_PATH):
    file_path = os.path.join(SOURCE_PATH, file_name)
    lines = read_lines_from_file(file_path)
    for line in lines:
        elements = line.split()
        if len(elements) == 5:
            print(file_name)   

This way I found that:

  1. I used this short script to asses if there are any label files that are empty:
import os

SOURCE_PATH = f"{HOME}/datasets/Car-Detection-Game-1/train/labels"

def read_lines_from_file(file_path):
    with open(file_path, 'r') as file:
        lines = file.readlines()
    return lines

for file_name in os.listdir(SOURCE_PATH):
    file_path = os.path.join(SOURCE_PATH, file_name)
    lines = read_lines_from_file(file_path)
    if len(lines) == 0:
        print(file_name)

This way I found that:

frame2133_jpg.rf.fa9549943e324ead3f81b5455091a22f.txt
frame289_jpg.rf.2c1de50c51c1da9fbfb99077b9e13a5d.txt
frame1902_jpg.rf.cbea12671eaefb8f77d2dc912dd37870.txt
frame1946_jpg.rf.582d9ba437d8725151a78d09ff6694a1.txt
frame2549_jpg.rf.c6dd21c59a0ba36d26b7743c61a85655.txt
frame2597_jpg.rf.58ccc97b5fef4def77e0c33476d19020.txt
frame2734_jpg.rf.7b6d6bf4ac441ccd31dea123fc30b180.txt
frame1489_jpg.rf.2be176a527e061e9134a83ebc25c4c13.txt
frame201_jpg.rf.d0b847928064830774a68d2102dbaaf2.txt
frame2552_jpg.rf.5eba2af3b5aabd29a5574a901b291b3a.txt
frame2733_jpg.rf.1aff9ca586d0a30b8a3d98aa65b27468.txt
frame1940_jpg.rf.8236623a74e7b222779a8a95fad2f96a.txt
frame197_jpg.rf.537a9821268b613dfc9b562068635948.txt
frame132_jpg.rf.ba4d20574fed6a872aed4a9742c6d457.txt
frame2315_jpg.rf.136b8f4f56f1721098eab4092d1aec49.txt
frame2591_jpg.rf.c208f7d3b725703468556658767e6d9c.txt
frame2592_jpg.rf.b1cc2a303288cfaa2319310b14232abe.txt
frame2445_jpg.rf.fd30d2d02908b1167a2ad9063ccf1967.txt
frame2691_jpg.rf.b7d1a3f2fcae8f0b5daca412b15d2895.txt
frame2296_jpg.rf.f824e42cd13e4132d4e302313c5de2b7.txt
frame2595_jpg.rf.47cf18994e4ee047e861143a1aeffebc.txt
frame1482_jpg.rf.873b19e9f30ea25aeedc533b67e63587.txt
frame2765_jpg.rf.bb6f659ef594e473361fb75008be321b.txt
frame2869_jpg.rf.fee4fc664ff8db16130d741f6a8be891.txt
frame2653_jpg.rf.b9460034c6ec1b22606ff316e9754582.txt
frame2390_jpg.rf.bea2f3d63a821128c26bbd9768766c30.txt

in train

frame2690_jpg.rf.fe260b30dec76fc52c5da47f5f13f27b.txt
frame2692_jpg.rf.d7f430b705e725009e374b7a14ae7b1d.txt
frame2714_jpg.rf.beee5d79760a5e05be8859140c1616c0.txt
frame1051_jpg.rf.a9e42a47913d2c5b6c6eafae78ee99c9.txt

in test

frame2890_jpg.rf.476b26a2682cc5ba3a41c4dd243ad474.txt
frame2806_jpg.rf.150d430301722b731a219c224e81e50b.txt
frame2454_jpg.rf.62ce899a54fc8e3e77d634fe98a539e0.txt
frame2391_jpg.rf.6279773432756867c687485137dbcbda.txt
frame2865_jpg.rf.adcbf3e0e6cd021d97cf7ed9405b33fa.txt

in valid

contain no bounding boxes and no polygons.

  1. I downloaded your dataset. Deleted those annotation files and related images. This way I ended up with 2071 images. I uploaded them back to roboflow: https://universe.roboflow.com/roboflow-jvuqo/car-detection-game-fixed
  2. Used that dataset for training and it works:

Screenshot 2023-04-24 at 13 18 08

  1. Here is my notebook: https://colab.research.google.com/drive/1wt8EKLLLANG9Ow2t_jNTH8Xe9VsgSf0E?usp=sharing
SkalskiP commented 1 year ago

I hope that will help you to train your model. I'm closing the issue for now. But feel free to reopen the issue if necessary.