File size: 3,412 Bytes
a4fc994
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d7fb0e1
a4fc994
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d7fb0e1
 
a4fc994
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# coding=utf-8
# Copyright 2021 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# 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.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Dataset class for Food-101 dataset."""

import datasets
from datasets.tasks import ImageClassification
import json
import requests


_HOMEPAGE = "https://huggingface.co/datasets/emanuelebezzecchi/trailerShotScale"

_DESCRIPTION = (
    "Shot scale has five categories: "
    "0) extreme close-up shot (ECS) shows even smaller parts such as the image of an eye or a mouth."
    "1) close-up shot (CS) concentrates on a relatively small object, showing the face of the hand of a person;" 
    "2) medium shot (MS) contains a figure from the knees or waist up;"
    "3) full shot (FS) barely includes the human body in full;"
    "4) long shot (LS) is taken from a long distance, sometimes as far as a quarter of a mile away;"    
)

_CITATION = """\
@inproceedings{rao2020unified,
title={A Unified Framework for Shot Type Classification Based on Subject Centric Lens},
author={Rao, Anyi and Wang, Jiaze and Xu, Linning and Jiang, Xuekun and Huang, Qingqiu and Zhou, Bolei and Lin, Dahua},
booktitle = {The European Conference on Computer Vision (ECCV)}, 
year={2020}
}
"""

_LICENSE = """\
LICENSE AGREEMENT
=================

"""

_NAMES      = ["ECS","CS","MS","FS","LS"]
_JSON_DIR   = "https://huggingface.co/datasets/emanuelebezzecchi/trailerShotScale/resolve/main/data.json"
_URL        = "https://huggingface.co/datasets/emanuelebezzecchi/trailerShotScale/resolve/main/images.tar.gz"

data = json.loads(requests.get(_JSON_DIR).content)
imgLabels = data['labels']


class trailerShotScale(datasets.GeneratorBasedBuilder):
    """trailerShotScale 10% of data, 5 images per folder respect to original"""

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "image": datasets.Image(),
                    "label": datasets.ClassLabel(names=_NAMES),
                }
            ),
            supervised_keys=("image", "label"),
            homepage=_HOMEPAGE,
            citation=_CITATION,
            license=_LICENSE,
            task_templates=[ImageClassification(image_column="image", label_column="label")],
        )

    def _split_generators(self, dl_manager):
        path        = dl_manager.download(_URL)
        image_iters = dl_manager.iter_archive(path)
        return [datasets.SplitGenerator(datasets.Split.TRAIN,gen_kwargs={"images":image_iters,})]
    

    def _generate_examples(self, images):
        """Generate images and labels for splits."""
        idx = 0
        #Iterate through images
        for filepath,image in images:
            yield idx, {
                "image":{"path":filepath, "bytes":image.read()},
                "label":imgLabels[idx]
            }
            idx += 1