oishee3003 commited on
Commit
0ce3c74
·
verified ·
1 Parent(s): 4fe7bf1

Upload dataset.py

Browse files
Files changed (1) hide show
  1. dataset.py +80 -0
dataset.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import DatasetInfo, GeneratorBasedBuilder, SplitGenerator, Split, Features, Value, ClassLabel, Image, Sequence
2
+ import csv
3
+ import datasets
4
+ import ast
5
+
6
+ class CAFOSatConfig(datasets.BuilderConfig):
7
+ def __init__(self, split_column="cafosat_set1_training_train", **kwargs):
8
+ super().__init__(**kwargs)
9
+ self.split_column = split_column
10
+
11
+ class CAFOSat(datasets.GeneratorBasedBuilder):
12
+ BUILDER_CONFIGS = [
13
+ CAFOSatConfig(name="set1_train", split_column="cafosat_set1_training_train", description="Set 1 training split"),
14
+ CAFOSatConfig(name="set1_val", split_column="cafosat_set1_training_val", description="Set 1 validation split"),
15
+ CAFOSatConfig(name="verified_train", split_column="cafosat_verified_training_train", description="Verified training split"),
16
+ CAFOSatConfig(name="all_train", split_column="cafosat_all_training_train", description="Verified training split"),
17
+ ]
18
+ DEFAULT_CONFIG_NAME = "all_train"
19
+
20
+ def _info(self):
21
+ return DatasetInfo(
22
+ description="CAFOSat: Remote sensing CAFO dataset with bounding boxes and infrastructure tags.",
23
+ features=Features({
24
+ "patch_file": Image(),
25
+ "label": ClassLabel(
26
+ names=["Negative", "Swine", "Dairy", "Beef", "Poultry", "Horses", "Sheep/Goats"]
27
+ ),
28
+ "barn": Value("float32"),
29
+ "manure_pond": Value("float32"),
30
+ "grazing_area": Value("float32"),
31
+ "others": Value("float32"),
32
+ "geom_bbox": Sequence(Value("float32")), # Keep as raw list
33
+ "category": Value("string"),
34
+ "state": Value("string"),
35
+ "image_type": Value("string"),
36
+ "CAFO_UNIQUE_ID": Value("string"),
37
+ "verified_label": Value("string"),
38
+ "patch_res": Value("string")
39
+ }),
40
+ supervised_keys=None,
41
+ homepage="https://huggingface.co/datasets/oishee3003/CAFOSat/",
42
+ license="cc-by-4.0"
43
+ )
44
+
45
+ def _split_generators(self, dl_manager):
46
+ csv_path = dl_manager.download_and_extract("cafosat.csv")
47
+ return [
48
+ SplitGenerator(name=Split.TRAIN, gen_kwargs={"csv_path": csv_path, "split_flag": self.config.split_column})
49
+ ]
50
+
51
+ def _generate_examples(self, csv_path, split_flag):
52
+ with open(csv_path, encoding="utf-8") as f:
53
+ reader = csv.DictReader(f)
54
+ for idx, row in enumerate(reader):
55
+ if row.get(split_flag, "0") != "1":
56
+ continue
57
+
58
+ # Parse bbox without scaling
59
+ try:
60
+ bbox = ast.literal_eval(row.get("geom_bbox", "[5.0, 5.0, 700.0, 700.0]"))
61
+ except:
62
+ bbox = [5.0, 5.0, 700.0, 700.0]
63
+
64
+ yield idx, {
65
+ "patch_file": row["patch_file"],
66
+ "label": int(row["label"]),
67
+ "barn": float(row.get("barn", 0)),
68
+ "manure_pond": float(row.get("manure_pond", 0)),
69
+ "grazing_area": float(row.get("grazing_area", 0)),
70
+ "others": float(row.get("others", 0)),
71
+ "geom_bbox": bbox, # ✅ unchanged
72
+ "category": row.get("category", ""),
73
+ "state": row.get("state", ""),
74
+ "image_type": row.get("image_type", ""),
75
+ "CAFO_UNIQUE_ID": row.get("CAFO_UNIQUE_ID", ""),
76
+ "verified_label": row.get("verified_label", ""),
77
+ "patch_res": row.get("patch_res", "")
78
+ "refine_x": row.get("refine_x", "")
79
+ "refine_y": row.get("refine_y", "")
80
+ }