Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ bash tools/dist_train.sh configs/soft_teacher/soft_teacher_faster_rcnn_r50_caffe
```
- To train model on **new dataset**:

The core idea is to convert a new dataset to coco format. Details about it can be found in the [adding new dataset](https://github.com/open-mmlab/mmdetection/blob/master/docs/tutorials/customize_dataset.md).
The core idea is to convert a new dataset to coco format. Details about it can be found in the [adding new dataset](https://github.com/open-mmlab/mmdetection/blob/master/docs/tutorials/customize_dataset.md). See also: tools/dataset/unlabeled_json.py



Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ torchvision
mmcv-full
wandb
prettytable
imagesize
4 changes: 4 additions & 0 deletions ssod/datasets/samplers/semi_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(
self.size_of_dataset = []
cumulative_sizes = [0] + self.cumulative_sizes

data_names = ['supervised', 'unsupervised']
for i, _ in enumerate(self.group_sizes):
size_of_dataset = 0
cur_group_inds = np.where(self.flag == i)[0]
Expand All @@ -62,6 +63,9 @@ def __init__(
)
)[0]
size_per_dataset = len(cur_group_cur_dataset)
assert size_per_dataset is not 0, (
f'{data_names[j]} dataset does not contain examples from both'
' h > w and w > h aspect ratio groups')
size_of_dataset = max(
size_of_dataset, np.ceil(size_per_dataset / self.sample_ratio[j])
)
Expand Down
47 changes: 47 additions & 0 deletions tools/dataset/unlabeled_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Generate unlabeled coco dataset json annotations from a folder of images.
Uses imagesize for significant speedup over reading images into memory.

Example:
python tools/unlabeled_json.py --img-dir <img/path/> --json-out <json/save/path.json>
"""

import argparse
import glob
import imagesize
import json


def folder_to_json(img_dir, json_out_path):

ext = ('*.jpg', '*.jpeg', '*.png')
paths = [p for paths in [glob.glob(img_dir + e) for e in ext]
for p in paths]
assert len(paths) > 0

images = []
for i, p in enumerate(paths):
w, h = imagesize.get(p)
name = p.split('/')[-1]

per_image_dict = dict(
id=i,
file_name=name,
width=w,
height=h
)

images.append(per_image_dict)

data = dict(categories=[])
data['images'] = images
with open(json_out_path, 'w') as f:
json.dump(data, f)

if __name__ == "__main__":

parser = argparse.ArgumentParser()
parser.add_argument("--img-dir", type=str)
parser.add_argument("--json-out", type=str)
args = parser.parse_args()

folder_to_json(args.img_dir, args.json_out)