OtoroLin commited on
Commit
bc49816
·
1 Parent(s): 7292dc0

Update building script

Browse files
Files changed (2) hide show
  1. HyperForensics-plus-plus.py +32 -54
  2. zipping.sh +12 -0
HyperForensics-plus-plus.py CHANGED
@@ -1,5 +1,3 @@
1
- # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
- #
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
  # you may not use this file except in compliance with the License.
5
  # You may obtain a copy of the License at
@@ -11,7 +9,7 @@
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
  # See the License for the specific language governing permissions and
13
  # limitations under the License.
14
- """TODO: Add a description here."""
15
 
16
 
17
  import csv
@@ -20,22 +18,17 @@ import os
20
 
21
  import datasets
22
 
23
-
24
- # TODO: Add BibTeX citation
25
- # Find for instance the citation on arxiv or on the dataset repo/website
26
  _CITATION = """\
27
- @InProceedings{huggingface:dataset,
28
- title = {A great new dataset},
29
- author={huggingface, Inc.
30
- },
31
- year={2020}
32
  }
33
  """
34
 
35
- # TODO: Add description of the dataset here
36
- # You can copy an official description
37
  _DESCRIPTION = """\
38
- This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
 
39
  """
40
 
41
  _HOMEPAGE = "https://huggingface.co/datasets/OtoroLin/HyperForensics-plus-plus"
@@ -43,17 +36,11 @@ _HOMEPAGE = "https://huggingface.co/datasets/OtoroLin/HyperForensics-plus-plus"
43
  # TODO: Add the licence for the dataset here if you can find it
44
  _LICENSE = ""
45
 
46
- # TODO: Add link to the official dataset URLs here
47
- # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
48
- # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
49
- _URLS = {
50
- "first_domain": "https://huggingface.co/great-new-dataset-first_domain.zip",
51
- "second_domain": "https://huggingface.co/great-new-dataset-second_domain.zip",
52
- }
53
 
54
 
55
  class HyperForensicsPlusPlus(datasets.GeneratorBasedBuilder):
56
- """TODO: Short description of my dataset."""
57
 
58
  VERSION = datasets.Version("1.1.0")
59
 
@@ -65,32 +52,27 @@ class HyperForensicsPlusPlus(datasets.GeneratorBasedBuilder):
65
  # data = datasets.load_dataset('my_dataset', 'first_domain')
66
  # data = datasets.load_dataset('my_dataset', 'second_domain')
67
  BUILDER_CONFIGS = [
68
- datasets.BuilderConfig(name="first_domain", version=VERSION, description="This part of my dataset covers a first domain"),
69
- datasets.BuilderConfig(name="second_domain", version=VERSION, description="This part of my dataset covers a second domain"),
 
 
 
70
  ]
71
 
72
- DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
73
 
74
  def _info(self):
75
- # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
76
- if self.config.name == "first_domain": # This is the name of the configuration selected in BUILDER_CONFIGS above
77
- features = datasets.Features(
78
- {
79
- "sentence": datasets.Value("string"),
80
- "option1": datasets.Value("string"),
81
- "answer": datasets.Value("string")
82
- # These are the features of your dataset like images, labels ...
83
- }
84
- )
85
- else: # This is an example to show how to have different features for "first_domain" and "second_domain"
86
- features = datasets.Features(
87
- {
88
- "sentence": datasets.Value("string"),
89
- "option2": datasets.Value("string"),
90
- "second_domain_answer": datasets.Value("string")
91
- # These are the features of your dataset like images, labels ...
92
- }
93
- )
94
  return datasets.DatasetInfo(
95
  # This is the description that will appear on the datasets page.
96
  description=_DESCRIPTION,
@@ -108,20 +90,17 @@ class HyperForensicsPlusPlus(datasets.GeneratorBasedBuilder):
108
  )
109
 
110
  def _split_generators(self, dl_manager):
111
- # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
112
- # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
113
-
114
  # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
115
  # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
116
  # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
117
- urls = _URLS[self.config.name]
118
  data_dir = dl_manager.download_and_extract(urls)
119
  return [
120
  datasets.SplitGenerator(
121
  name=datasets.Split.TRAIN,
122
  # These kwargs will be passed to _generate_examples
123
  gen_kwargs={
124
- "filepath": os.path.join(data_dir, "train.jsonl"),
125
  "split": "train",
126
  },
127
  ),
@@ -129,15 +108,15 @@ class HyperForensicsPlusPlus(datasets.GeneratorBasedBuilder):
129
  name=datasets.Split.VALIDATION,
130
  # These kwargs will be passed to _generate_examples
131
  gen_kwargs={
132
- "filepath": os.path.join(data_dir, "dev.jsonl"),
133
- "split": "dev",
134
  },
135
  ),
136
  datasets.SplitGenerator(
137
  name=datasets.Split.TEST,
138
  # These kwargs will be passed to _generate_examples
139
  gen_kwargs={
140
- "filepath": os.path.join(data_dir, "test.jsonl"),
141
  "split": "test"
142
  },
143
  ),
@@ -145,8 +124,7 @@ class HyperForensicsPlusPlus(datasets.GeneratorBasedBuilder):
145
 
146
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
147
  def _generate_examples(self, filepath, split):
148
- # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
149
- # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
150
  with open(filepath, encoding="utf-8") as f:
151
  for key, row in enumerate(f):
152
  data = json.loads(row)
 
 
 
1
  # Licensed under the Apache License, Version 2.0 (the "License");
2
  # you may not use this file except in compliance with the License.
3
  # You may obtain a copy of the License at
 
9
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
  # See the License for the specific language governing permissions and
11
  # limitations under the License.
12
+ """HyperForensics++ dataset"""
13
 
14
 
15
  import csv
 
18
 
19
  import datasets
20
 
 
 
 
21
  _CITATION = """\
22
+ @InProceedings{hyperforensics:dataset,
23
+ title={HyperForensics++: Toward Adversarial Perturbed and Object Replacement in Hyperspectral Imaging Dataset},
24
+ author={Chih-Chung Hsu, Chia-Ming Lee, Min-Tzo Ko, En-Chao Liu, Yi-Ching Cheng, Ming-Ching Chang},
25
+ year={2025}
 
26
  }
27
  """
28
 
 
 
29
  _DESCRIPTION = """\
30
+ The HyperForensics++ dataset is an advanced benchmark designed for hyperspectral image (HSI) forgery detection.
31
+ It builds upon the foundational HyperForensics dataset by introducing new manipulation scenarios and enhanced techniques.
32
  """
33
 
34
  _HOMEPAGE = "https://huggingface.co/datasets/OtoroLin/HyperForensics-plus-plus"
 
36
  # TODO: Add the licence for the dataset here if you can find it
37
  _LICENSE = ""
38
 
39
+ _URL = "https://huggingface.co/datasets/OtoroLin/HyperForensics-plus-plus/resolve/main/data.tar.gz"
 
 
 
 
 
 
40
 
41
 
42
  class HyperForensicsPlusPlus(datasets.GeneratorBasedBuilder):
43
+ """HyperForensics++ dataset"""
44
 
45
  VERSION = datasets.Version("1.1.0")
46
 
 
52
  # data = datasets.load_dataset('my_dataset', 'first_domain')
53
  # data = datasets.load_dataset('my_dataset', 'second_domain')
54
  BUILDER_CONFIGS = [
55
+ datasets.BuilderConfig(
56
+ name="data",
57
+ version=VERSION,
58
+ description="Full dataset with all the HSI in npy format",),
59
+ # datasets.BuilderConfig(name="second_domain", version=VERSION, description="This part of my dataset covers a second domain"),
60
  ]
61
 
62
+ DEFAULT_CONFIG_NAME = "data" # It's not mandatory to have a default configuration. Just use one if it make sense.
63
 
64
  def _info(self):
65
+ features = datasets.Features(
66
+ {
67
+ "origin": datasets.Image(), # The original HSI
68
+ "label": datasets.Value("string"), # The label of the image
69
+ "forgery": datasets.Image(), # The HSI after forgery
70
+ "method": datasets.Value("string"), # The forgery method used
71
+ # The bounding box of the forgery area, in the format [x1, x2, y1, y2, z1, y2]
72
+ "bbox": datasets.Sequence(feature=datasets.Value(dtype='int8'), length=6)
73
+ }
74
+ )
75
+
 
 
 
 
 
 
 
 
76
  return datasets.DatasetInfo(
77
  # This is the description that will appear on the datasets page.
78
  description=_DESCRIPTION,
 
90
  )
91
 
92
  def _split_generators(self, dl_manager):
 
 
 
93
  # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
94
  # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
95
  # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
96
+ urls = _URL
97
  data_dir = dl_manager.download_and_extract(urls)
98
  return [
99
  datasets.SplitGenerator(
100
  name=datasets.Split.TRAIN,
101
  # These kwargs will be passed to _generate_examples
102
  gen_kwargs={
103
+ "filepath": os.path.join(data_dir, "metadata.jsonl"),
104
  "split": "train",
105
  },
106
  ),
 
108
  name=datasets.Split.VALIDATION,
109
  # These kwargs will be passed to _generate_examples
110
  gen_kwargs={
111
+ "filepath": os.path.join(data_dir, "metadata.jsonl"),
112
+ "split": "val",
113
  },
114
  ),
115
  datasets.SplitGenerator(
116
  name=datasets.Split.TEST,
117
  # These kwargs will be passed to _generate_examples
118
  gen_kwargs={
119
+ "filepath": os.path.join(data_dir, "metadata.jsonl"),
120
  "split": "test"
121
  },
122
  ),
 
124
 
125
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
126
  def _generate_examples(self, filepath, split):
127
+
 
128
  with open(filepath, encoding="utf-8") as f:
129
  for key, row in enumerate(f):
130
  data = json.loads(row)
zipping.sh ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Define the folder to zip and the output zip file
4
+ FOLDER_TO_ZIP="../data"
5
+ OUTPUT_TAR="./data.tar.gz"
6
+
7
+ # Create the zip file
8
+ echo "Zipping folder: $FOLDER_TO_ZIP"
9
+ tar -czvf "$OUTPUT_TAR" "$FOLDER_TO_ZIP"
10
+
11
+ # Confirm completion
12
+ echo "Folder zipped successfully to: $OUTPUT_TAR"