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
4 changes: 2 additions & 2 deletions config/detection/ssd_coco/mobilevit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ common:
auto_resume: true
mixed_precision: true
dataset:
root_train: "/mnt/vision_datasets/coco"
root_val: "/mnt/vision_datasets/coco"
root_train: "/content/data/train2017"
root_val: "/content/data/val2017"
name: "coco_ssd"
category: "detection"
train_batch_size0: 32 # effective batch size is 128 (32 * 4 GPUs)
Expand Down
14 changes: 11 additions & 3 deletions data/datasets/detection/coco_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(
logger.disable_printing()

self.coco = COCO(ann_file)
self.img_dir = os.path.join(self.root, "images/{}{}".format(split, year))
self.img_dir = self.root
self.ids = (
list(self.coco.imgToAnns.keys())
if self.is_training
Expand Down Expand Up @@ -139,9 +139,17 @@ def __getitem__(

transform_fn = self.get_augmentation_transforms(size=(crop_size_h, crop_size_w))

image_id = self.ids[img_index]
num_images = len(self.ids)
for _ in range(num_images):
image_id = self.ids[img_index]

image, img_name = self.get_image(image_id=image_id)
image, img_name = self.get_image(image_id=image_id)
if image is not None:
break
# corrupted image; try next
img_index = (img_index + 1) % num_images
else:
raise RuntimeError("All images in the dataset are corrupted.")
im_width, im_height = image.size

boxes, labels, mask = self.get_boxes_and_labels(
Expand Down
2 changes: 1 addition & 1 deletion data/datasets/segmentation/coco_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, opts: argparse.Namespace, *args, **kwargs) -> None:
ann_file = os.path.join(
self.root, "annotations/instances_{}{}.json".format(split, year)
)
self.img_dir = os.path.join(self.root, "images/{}{}".format(split, year))
self.img_dir = self.root
self.split = split
self.coco = COCO(ann_file)
self.coco_mask = mask
Expand Down
12 changes: 11 additions & 1 deletion data/text_tokenizer/clip_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,26 @@

import torch
from torch import Tensor
from torchtext.transforms import CLIPTokenizer

from data.text_tokenizer import TOKENIZER_REGISTRY, BaseTokenizer
from utils import logger
from utils.download_utils import get_local_path

try:
from torchtext.transforms import CLIPTokenizer
except (ImportError, OSError):
CLIPTokenizer = None


@TOKENIZER_REGISTRY.register(name="clip")
class ClipTokenizer(BaseTokenizer):
def __init__(self, opts, *args, **kwargs):
if CLIPTokenizer is None:
logger.error(
"torchtext is not available. Please install a compatible version "
"of torchtext to use the CLIP tokenizer."
)

merges_path = getattr(opts, "text_tokenizer.clip.merges_path", None)
if merges_path is None:
logger.error(
Expand Down
20 changes: 19 additions & 1 deletion data/transforms/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,27 @@
import torch
import torchaudio
from torch.nn import functional as F
from torchvision.io import write_video
from torchvision.transforms import functional as FV

try:
import cv2

def write_video(filename: str, video_array: torch.Tensor, fps: float):
"""Write video using OpenCV (replacement for removed torchvision.io.write_video)."""
video_array = video_array.cpu().numpy() # (N, H, W, C) uint8
n_frames = video_array.shape[0]
h, w = video_array.shape[1:3]
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
out = cv2.VideoWriter(str(filename), fourcc, fps, (w, h))
for i in range(n_frames):
frame = video_array[i]
# cv2 expects BGR
frame_bgr = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
out.write(frame_bgr)
out.release()
except ImportError:
from torchvision.io import write_video

from data.transforms import TRANSFORMATIONS_REGISTRY, BaseTransformation
from data.transforms.utils import *
from options.parse_args import JsonValidator
Expand Down
4 changes: 2 additions & 2 deletions main_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,5 @@ def main_worker_detection(args: Optional[List[str]] = None, **kwargs):

if __name__ == "__main__":
# main_worker()
main_worker_segmentation()
# main_worker_detection()
#main_worker_segmentation()
main_worker_detection()