LeoZhangzaolin
commited on
Commit
•
d635639
1
Parent(s):
8be8808
Update Graptolodiea-Speciemens-Imaging.py
Browse files
Graptolodiea-Speciemens-Imaging.py
CHANGED
@@ -6,63 +6,115 @@ from typing import List
|
|
6 |
import datasets
|
7 |
import pandas as pd
|
8 |
import numpy as np
|
|
|
|
|
|
|
|
|
9 |
|
10 |
_CITATION = """\
|
11 |
-
|
12 |
-
"""
|
13 |
-
|
14 |
-
|
15 |
|
16 |
_DESCRIPTION = """\
|
17 |
-
|
18 |
-
The Graptoloidea Specimens Imaging dataset is a curated collection of over 1,300 image-text pairs, focusing on Graptoloidea specimens. It encompasses detailed attributes such as species classification, geological stages, and specific locality information (with coordinates), complemented by high-quality images of each specimen. This dataset serves as a valuable resource for paleontological research, offering insights into the morphological diversity and geological distribution of Graptoloidea.
|
19 |
-
|
20 |
-
Highlights:
|
21 |
-
- Comprehensive Collection: Over 1,300 unique specimens, each with a corresponding high-quality image and descriptive text.
|
22 |
-
- Diverse Geological Coverage: Specimens span different geological stages, offering a timeline of the Graptoloidea evolution.
|
23 |
-
- Rich Annotations: Apart from visual data, the dataset includes detailed taxonomic classification, geological context, and precise locality information.
|
24 |
-
- Research-Ready: Ideal for tasks like paleontological classification, morphological analysis, age estimation, and geographical distribution studies.
|
25 |
-
- Educational Value: Serves as an invaluable resource for educational and outreach programs, providing tangible insights into paleontology.
|
26 |
"""
|
27 |
|
28 |
-
|
29 |
_HOMEPAGE = "https://zenodo.org/records/6194943"
|
30 |
-
|
31 |
-
|
32 |
-
_license = ""
|
33 |
-
|
34 |
-
|
35 |
-
_URLS = {
|
36 |
-
"part1": "https://zenodo.org/records/6194943/files/graptolite%20specimens%20with%20scale.zip.001?download=1",
|
37 |
-
"part2": "https://zenodo.org/records/6194943/files/graptolite%20specimens%20with%20scale.zip.002?download=1",
|
38 |
-
}
|
39 |
-
|
40 |
|
41 |
class GraptoloideaSpecimensDataset(datasets.GeneratorBasedBuilder):
|
42 |
-
|
43 |
-
|
44 |
|
45 |
def _info(self):
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
|
68 |
|
|
|
6 |
import datasets
|
7 |
import pandas as pd
|
8 |
import numpy as np
|
9 |
+
import csv
|
10 |
+
import logging
|
11 |
+
from PIL import Image
|
12 |
+
import ast
|
13 |
|
14 |
_CITATION = """\
|
15 |
+
111
|
16 |
+
"""
|
|
|
|
|
17 |
|
18 |
_DESCRIPTION = """\
|
19 |
+
[Your dataset description here...]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
"""
|
21 |
|
|
|
22 |
_HOMEPAGE = "https://zenodo.org/records/6194943"
|
23 |
+
_license = "111"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
class GraptoloideaSpecimensDataset(datasets.GeneratorBasedBuilder):
|
26 |
+
_URL = "https://raw.githubusercontent.com/LeoZhangzaolin/photos/main/Final_GS_with_Images.csv"
|
|
|
27 |
|
28 |
def _info(self):
|
29 |
+
return datasets.DatasetInfo(
|
30 |
+
description=_DESCRIPTION,
|
31 |
+
features=datasets.Features(
|
32 |
+
{
|
33 |
+
"Suborder": datasets.Value("string"),
|
34 |
+
"Infraorder": datasets.Value("string"),
|
35 |
+
"Family (Subfamily)": datasets.Value("string"),
|
36 |
+
"Genus": datasets.Value("string"),
|
37 |
+
"Tagged Species Name": datasets.Value("string"),
|
38 |
+
"Image": datasets.Value("string"),
|
39 |
+
"Stage": datasets.Value("string"),
|
40 |
+
"Mean Age Value": datasets.Value("float64"),
|
41 |
+
"Locality (Longitude, Latitude, Horizon)": datasets.Value("string"),
|
42 |
+
"Reference (Specimens Firstly Published)": datasets.Value("string"),
|
43 |
+
}
|
44 |
+
),
|
45 |
+
supervised_keys=None,
|
46 |
+
homepage=_HOMEPAGE,
|
47 |
+
citation=_CITATION,
|
48 |
+
)
|
49 |
+
|
50 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
51 |
+
downloaded_file = dl_manager.download_and_extract(self._URL)
|
52 |
+
|
53 |
+
# Read the CSV file
|
54 |
+
df = pd.read_csv(downloaded_file)
|
55 |
+
df = df.sample(frac=1).reset_index(drop=True) # Shuffle the dataset
|
56 |
+
|
57 |
+
# Splitting the dataset
|
58 |
+
train_size = int(0.7 * len(df))
|
59 |
+
test_size = int(0.15 * len(df))
|
60 |
+
|
61 |
+
train_df = df[:train_size]
|
62 |
+
test_df = df[train_size:train_size + test_size]
|
63 |
+
validation_df = df[train_size + test_size:]
|
64 |
+
|
65 |
+
# Save split dataframes to temporary CSV files
|
66 |
+
train_file = '/tmp/train_split.csv'
|
67 |
+
test_file = '/tmp/test_split.csv'
|
68 |
+
validation_file = '/tmp/validation_split.csv'
|
69 |
+
|
70 |
+
train_df.to_csv(train_file, index=False)
|
71 |
+
test_df.to_csv(test_file, index=False)
|
72 |
+
validation_df.to_csv(validation_file, index=False)
|
73 |
+
|
74 |
+
return [
|
75 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_file}),
|
76 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_file}),
|
77 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": validation_file}),
|
78 |
+
]
|
79 |
+
|
80 |
+
def _generate_examples(self, filepath):
|
81 |
+
"""This function returns the examples from the CSV file."""
|
82 |
+
logging.info("generating examples from = %s", filepath)
|
83 |
+
with open(filepath, encoding='utf-8') as f:
|
84 |
+
reader = csv.DictReader(f)
|
85 |
+
key = 0
|
86 |
+
for row in reader:
|
87 |
+
key += 1
|
88 |
+
# Extracting data from each column
|
89 |
+
suborder = row['Suborder'].strip()
|
90 |
+
infraorder = row['Infraorder'].strip()
|
91 |
+
family_subfamily = row['Family (Subfamily)'].strip()
|
92 |
+
genus = row['Genus'].strip()
|
93 |
+
species_name = row['tagged species name'].strip()
|
94 |
+
image = row['image'].strip()
|
95 |
+
stage = row['Stage'].strip()
|
96 |
+
mean_age = row['mean age value']
|
97 |
+
locality = row['Locality (Longitude, Latitude, Horizon)'].strip()
|
98 |
+
reference = row['Reference (specimens firstly published)'].strip()
|
99 |
+
|
100 |
+
# Constructing the example
|
101 |
+
yield key, {
|
102 |
+
"Suborder": suborder,
|
103 |
+
"Infraorder": infraorder,
|
104 |
+
"Family (Subfamily)": family_subfamily,
|
105 |
+
"Genus": genus,
|
106 |
+
"Tagged Species Name": species_name,
|
107 |
+
"Image": image,
|
108 |
+
"Stage": stage,
|
109 |
+
"Mean Age Value": mean_age,
|
110 |
+
"Locality (Longitude, Latitude, Horizon)": locality,
|
111 |
+
"Reference (Specimens Firstly Published)": reference,
|
112 |
+
}
|
113 |
+
|
114 |
+
|
115 |
+
|
116 |
+
|
117 |
+
|
118 |
|
119 |
|
120 |
|