# coding=utf-8 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. """DAVIS 2017 (semi-supervised video object segmentation), packaged as a Hugging Face dataset. One row per frame, so a split streams frame by frame and a single frame is one lookup; the rows of a video are contiguous and in frame order, and carry the video name, so a video is a groupby: load_dataset('/davis2017', 'semi-supervised') # 60 train / 30 val videos, 480p Images are the official 480p JPEGs and masks the official annotation PNGs, both copied through byte for byte. Masks are palette (mode P) PNGs whose pixel value is the object id of the video (0 = background, 1..N = objects, 255 = void), which is the encoding DAVIS ships and the one its evaluation reads. Object ids are per video, not classes: object 1 of one video has nothing to do with object 1 of another. Only the trainval set is packed. The test-dev and test-challenge sets ship first-frame masks only, so they cannot be scored offline. Source data comes from an unpacked DAVIS folder when one is given, and is downloaded from the official host otherwise: python create_dataset.py --repo /davis2017 --davis-root ~/Data/datasets/DAVIS --private DAVIS_ROOT=~/Data/datasets/DAVIS python create_dataset.py --repo /davis2017 Build without uploading anything, to check the result first: python create_dataset.py --dry-run --limit 2 """ import argparse import glob import os import datasets import numpy as np from PIL import Image _VERSION = "1.0.0" _HOMEPAGE_URL = "https://davischallenge.org/davis2017/code.html" _DOWNLOAD_URL = "https://data.vision.ee.ethz.ch/csergi/share/davis/DAVIS-2017-trainval-480p.zip" _CITATION = """\ @article{Pont-Tuset_arXiv_2017, author = {Jordi Pont-Tuset and Federico Perazzi and Sergi Caelles and Pablo Arbel\\'aez and Alexander Sorkine-Hornung and Luc {Van Gool}}, title = {The 2017 DAVIS Challenge on Video Object Segmentation}, journal = {arXiv:1704.00675}, year = {2017} } @inproceedings{Perazzi_CVPR_2016, author = {Federico Perazzi and Jordi Pont-Tuset and Brian McWilliams and Luc {Van Gool} and Markus Gross and Alexander Sorkine-Hornung}, title = {A Benchmark Dataset and Evaluation Methodology for Video Object Segmentation}, booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)}, year = {2016} } """ _LICENSE = """\ DAVIS 2017 is released under CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/). The videos come from online sources listed in SOURCES.md, which keep their own terms of use. This packaging adds no rights: use it under those same terms and cite the original work. """ _DESCRIPTION = """\ DAVIS 2017 semi-supervised video object segmentation at 480p, one row per frame: the 60 train and 30 val videos of the official trainval set with their multi-object masks. Masks are palette PNGs whose pixel value is the object id within the video (0 background, 255 void). """ SEMI_SUPERVISED = "semi-supervised" # Videos and frames of the official 2017 split lists. Checked against what was built before # anything is pushed: a stale cache or a half-unpacked root shows up first as wrong counts. EXPECTED_SIZES = {SEMI_SUPERVISED: {"train": 4209, "validation": 1999}} EXPECTED_VIDEOS = {SEMI_SUPERVISED: {"train": 60, "validation": 30}} _VOID_INDEX = 255 def read_split(root, split): """The video names of one split, read from the ImageSets list that names it.""" with open(os.path.join(root, "ImageSets", "2017", split + ".txt")) as f: return [line.strip() for line in f if line.strip()] def first_frame_objects(mask_path): """Number of objects of a video: the largest id of its first-frame mask, void excluded.""" mask = np.array(Image.open(mask_path)) ids = mask[mask != _VOID_INDEX] return int(ids.max()) if ids.size else 0 class DAVIS2017Config(datasets.BuilderConfig): """One task view over the DAVIS videos.""" def __init__(self, resolution="480p", davis_root=None, limit=None, **kwargs): super().__init__(version=datasets.Version(_VERSION, ""), **kwargs) self.resolution = resolution # davis_root and limit are config fields so that they reach the builder and enter the # config id: a truncated build lands in its own cache directory and is never served back # to a full one. self.davis_root = davis_root self.limit = limit class DAVIS2017(datasets.GeneratorBasedBuilder): """DAVIS 2017, one row per frame.""" BUILDER_CONFIGS = [ DAVIS2017Config( name=SEMI_SUPERVISED, resolution="480p", description=( "Semi-supervised video object segmentation on the official trainval set at 480p, " "the resolution of the official evaluation: 60 train and 30 val videos, every frame " "with its multi-object mask. The task gives the first-frame mask and scores the rest." ), ) ] DEFAULT_CONFIG_NAME = SEMI_SUPERVISED def _info(self): features = { "id": datasets.Value("string"), #