detecto icon indicating copy to clipboard operation
detecto copied to clipboard

Losses come out to be None, as if the model isn't training on the data

Open iHasna opened this issue 4 years ago • 3 comments

Environment: Google Colab with GPU

This is more of an issue than a bug. I'm running everything with no errors thankfully. But its as if the model is not running or finding anything in my datasets. I added my images and XML files to the same folder 'Images' like it was mentioned to do in the medium article. I do want to note that some images don't have XML files cause there was no object in the image but I believe that to be fine because the 300+ images do have the object 'table'. I even ran the utils.xml_to_csv to make sure the xml files were being read and it was. This is the result: image

I then run the next few lines as shown in the tutorial:

`dataset = core.Dataset('/content/train_labels.csv', '/content/Images/')
loader = core.DataLoader(dataset, batch_size=3, shuffle=True)

model = core.Model(sni)
losses = model.fit(loader, epochs=7,
                   learning_rate=0.001, verbose=True)`

And everything runs: image

I then get this error: image

The losses are none? As if its not training on anything? I can't seem to see where the problem is.

iHasna avatar Apr 08 '21 17:04 iHasna

You have to pass in a validation dataset/loader as the second argument to model.fit (or the keyword argument val_dataset) in order for it to return a list of losses. So something like this:

dataset = core.Dataset('/content/train_labels.csv', '/content/Images/')
loader = core.DataLoader(dataset, batch_size=3, shuffle=True)

validation = ...  # initialize your validation dataset (either core.Dataset or core.DataLoader object)

model = core.Model(sni)
losses = model.fit(loader, validation, epochs=7, learning_rate=0.001, verbose=True)

alankbi avatar Apr 09 '21 03:04 alankbi

Ah okay thanks for letting me know. However, when I try to predict on an image I used for training I get empty lists. Code below: image

(idk why it turns it yellow, its originally white.)

image

image

iHasna avatar Apr 09 '21 15:04 iHasna

That likely means the model wasn't trained well enough in order to detect any objects. You could try printing or plotting the returned list of losses (if you have a validation dataset specified) to see if the loss is continuously decreasing (maybe you need more epochs), or potentially add additional images or augmentations to strengthen your dataset.

alankbi avatar Apr 10 '21 00:04 alankbi