Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError #1

Closed
kimo20200 opened this issue Sep 15, 2021 · 11 comments
Closed

AssertionError #1

kimo20200 opened this issue Sep 15, 2021 · 11 comments

Comments

@kimo20200
Copy link

kimo20200 commented Sep 15, 2021

Hello,

I got an error when I tried to train the model. I have attached a link in the box. Do you have any idea about it?
Thank you.

link: https://drive.google.com/file/d/14cI1BLo7FZQ8IhGBuGoUzsXJtEEtlp65/view?usp=sharing

Best wishes,
Qing

@LLYXC
Copy link
Owner

LLYXC commented Sep 15, 2021

Thanks for the interest in OXnet. I can't find the screenshot anywhere. Would you please try again?

@kimo20200
Copy link
Author

I have updated it, sorry for that. Please see the first box

@LLYXC
Copy link
Owner

LLYXC commented Sep 15, 2021

In the current version of OXnet, we are sampling two types of data in one batch: labeled data and unlabeled data. Hence, you can see the usage of a two-stream batch sampler. The reported error is caused by

assert len(self.secondary_indices) >= self.secondary_batch_size > 0
which means:

  1. the size of the second batch of data (for unlabeled data) should be at least 1;
  2. the total number of the unlabeled data should be larger than or equal to the second batch size (defined as follows:)
    labeled_batch, unlabeled_batch = 2, 2

@kimo20200
Copy link
Author

Thanks for your reply, I have prepared my own train (labeled) dataset with coco-liked format, but where the unlabeled data I should include. I am confused about it.

@LLYXC
Copy link
Owner

LLYXC commented Sep 15, 2021

You can create two COCO-style json files for labeled data and unlabeled data and merge these two in one single json file. Say you have N labeled data, and M unlabeled data, then the beginning N data in the merged file should be labeled ones and the followed M data are the unlabeled ones. Set N and N+M to be num_labeled_data and num_data in the following:

OXnet/train_oxnet.py

Lines 121 to 125 in 2c99bb5

labeled_idxs = list(range(parser.num_labeled_data))
unlabeled_idxs = list(range(parser.num_labeled_data, parser.num_data))
labeled_batch, unlabeled_batch = 2, 2
batch_sampler = TwoStreamBatchSampler(labeled_idxs, unlabeled_idxs, labeled_batch, unlabeled_batch)
dataloader_train = DataLoader(dataset_train, num_workers=8, collate_fn=tuple_collater, batch_sampler=batch_sampler)

Note you can give empty or negative values to the annotations for the unlabeled data, these would not be included in the training.
Thanks for pointing this out. I will clarify the instruction.

@kimo20200
Copy link
Author

Very appreciate your clear demonstration and could you show an example of the json file or structure? I think it is easy for users to understand it.

@LLYXC
Copy link
Owner

LLYXC commented Sep 15, 2021

A COCO-style json file would be a dictionary with the structure like follows:
dict_keys(['categories', 'images', 'annotations'])
Say you now have a json file for the labeled data (labeled.json), and a json file the for unlabeled data (unlabeled.json), you can merge these into a single file for training as follows:

import json as js
js_l = js.load('labeled.json')
js_u = js.load('unlabeled.json')
merged = {'categories': js_l['categories'],
          'images' : js_l['images'] + js_u ['images'] ,
          'annotations': js_l['annotations'] + js_u ['annotations']}
with open('train.json', 'w') as f:
    js.dump(merged, f)

@kimo20200
Copy link
Author

Thank you a lot, I will try it later

@kimo20200
Copy link
Author

Hi, when I was training, the Cls Cons loss and Reg Cons loss were always 0. They were calculated by soft focal loss. Does it means I add a incorrect unlabeled dataset?

@LLYXC
Copy link
Owner

LLYXC commented Sep 17, 2021

You may need to pre-train a RetinaNet and use the weights to initialize the teacher model so that the teacher model could generate meaningful pseudo labels to be used in the soft focal loss.
I think the mentioned problem might be that the teacher model does not generate pseudo labels.

@kimo20200
Copy link
Author

Cool. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants