File size: 1,785 Bytes
ac9629c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from datasets import DatasetInfo, GeneratorBasedBuilder, Split, SplitGenerator, Value, Image, ClassLabel

_CATEGORIES = ["buildings", "forest", "glacier", "mountain", "sea", "street"]

class IntelImageClassification(GeneratorBasedBuilder):
    def _info(self):
        return DatasetInfo(
            description="Intel Image Classification dataset with 6 natural scene categories.",
            features={
                "image": Image(),
                "label": ClassLabel(names=_CATEGORIES),
            },
            supervised_keys=("image", "label"),
            homepage="https://www.kaggle.com/datasets/puneet6060/intel-image-classification",
            # citation="Puneet Jindal, Intel Image Classification (Kaggle Dataset)",
        )

    def _split_generators(self, dl_manager):
        data_dir = os.path.join(dl_manager.manual_dir, "data")
        return [
            SplitGenerator(name=Split.TRAIN, gen_kwargs={"filepath": os.path.join(data_dir, "seg_train")}),
            SplitGenerator(name=Split.TEST, gen_kwargs={"filepath": os.path.join(data_dir, "seg_test")}),
            SplitGenerator(name=Split.VALIDATION, gen_kwargs={"filepath": os.path.join(data_dir, "seg_pred")}),
        ]

    def _generate_examples(self, filepath):
        idx = 0
        for label in sorted(os.listdir(filepath)):
            label_path = os.path.join(filepath, label)
            if not os.path.isdir(label_path):
                continue
            for img_file in sorted(os.listdir(label_path)):
                if img_file.lower().endswith((".jpg", ".jpeg", ".png")):
                    yield idx, {
                        "image": os.path.join(label_path, img_file),
                        "label": label,
                    }
                    idx += 1