osv5m commited on
Commit
7c96b72
1 Parent(s): 5a6a59f

Upload 2 files

Browse files
Files changed (2) hide show
  1. README.md +12 -1
  2. osv5m.py +127 -0
README.md CHANGED
@@ -1,3 +1,14 @@
1
  ---
2
  license: cc-by-sa-4.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: cc-by-sa-4.0
3
+ configs:
4
+ - config_name: default
5
+ data_files:
6
+ - split: train
7
+ path:
8
+ - "train.csv"
9
+ - "images/train"
10
+ - split: test
11
+ path:
12
+ - "test.csv"
13
+ - "images/test"
14
+ ---
osv5m.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pandas as pd
3
+ import datasets
4
+ from os.path import join
5
+
6
+ # convert these to features
7
+ #id,latitude,longitude,thumb_original_url,country,sequence,captured_at,lon_bin,lat_bin,cell,region,sub-region,city,land_cover,road_index,drive_side,climate,soil,dist_sea,quadtree_10_5000,quadtree_10_25000,quadtree_10_1000,quadtree_10_50000,quadtree_10_12500,quadtree_10_500,quadtree_10_2500,unique_region,unique_sub-region,unique_city,unique_country,creator_username,creator_id
8
+ #3859149887465501,-43.804769384023,-176.61409250805,,8,"(0, 8)",Chatham Islands,,Waitangi,4,4.661764145,1,15,3,0.0068841379890803,0,0,0,0,0,0,0,Chatham Islands_NZ,,Waitangi_NaN_Chatham Islands_NZ,NZ,roadroid,111336221091714.0
9
+
10
+ class OSV5M(datasets.GeneratorBasedBuilder):
11
+ def __init__(self, *args, **kwargs):
12
+ self.full = kwargs.pop('full', False)
13
+ super().__init__(*args, **kwargs)
14
+ print('OSV5M', self.__dict__)
15
+
16
+ def _info(self):
17
+ if self.full:
18
+ return datasets.DatasetInfo(
19
+ features=datasets.Features(
20
+ {
21
+ "image": datasets.Image(),
22
+ "latitude": datasets.Value("float32"),
23
+ "longitude": datasets.Value("float32"),
24
+ "thumb_original_url": datasets.Value("string"),
25
+ "country": datasets.Value("string"),
26
+ "sequence": datasets.Value("string"),
27
+ "captured_at": datasets.Value("string"),
28
+ "lon_bin": datasets.Value("float32"),
29
+ "lat_bin": datasets.Value("float32"),
30
+ "cell": datasets.Value("string"),
31
+ "region": datasets.Value("string"),
32
+ "sub-region": datasets.Value("string"),
33
+ "city": datasets.Value("string"),
34
+ "land_cover": datasets.Value("float32"),
35
+ "road_index": datasets.Value("float32"),
36
+ "drive_side": datasets.Value("float32"),
37
+ "climate": datasets.Value("float32"),
38
+ "soil": datasets.Value("float32"),
39
+ "dist_sea": datasets.Value("float32"),
40
+ "quadtree_10_5000": datasets.Value("int32"),
41
+ "quadtree_10_25000": datasets.Value("int32"),
42
+ "quadtree_10_1000": datasets.Value("int32"),
43
+ "quadtree_10_50000": datasets.Value("int32"),
44
+ "quadtree_10_12500": datasets.Value("int32"),
45
+ "quadtree_10_500": datasets.Value("int32"),
46
+ "quadtree_10_2500": datasets.Value("int32"),
47
+ "unique_region": datasets.Value("string"),
48
+ "unique_sub-region": datasets.Value("string"),
49
+ "unique_city": datasets.Value("string"),
50
+ "unique_country": datasets.Value("string"),
51
+ "creator_username": datasets.Value("string"),
52
+ "creator_id": datasets.Value("string"),
53
+ }
54
+ )
55
+ )
56
+ else:
57
+ return datasets.DatasetInfo(
58
+ features=datasets.Features(
59
+ {
60
+ "image": datasets.Image(),
61
+ "latitude": datasets.Value("float32"),
62
+ "longitude": datasets.Value("float32"),
63
+ "country": datasets.Value("string"),
64
+ "region": datasets.Value("string"),
65
+ "sub-region": datasets.Value("string"),
66
+ "city": datasets.Value("string"),
67
+ }
68
+ )
69
+ )
70
+
71
+ def df(self, annotation_path):
72
+ if not hasattr(self, 'df_'):
73
+ self.df_ = {}
74
+ if annotation_path not in self.df_:
75
+ df = pd.read_csv(annotation_path, dtype={
76
+ 'id': str, 'creator_id': str, 'creator_username': str,
77
+ 'unique_country': str, 'unique_city': str, 'unique_sub-region': str, 'unique_region': str,
78
+ 'quadtree_10_2500': int, 'quadtree_10_500': int, 'quadtree_10_12500': int, 'quadtree_10_50000': int, 'quadtree_10_1000': int, 'quadtree_10_25000': int, 'quadtree_10_5000': int,
79
+ 'dist_sea': float, 'soil': float, 'climate': float, 'drive_side': float, 'road_index': float, 'land_cover': float, 'city': str, 'sub-region': str, 'region': str, 'cell': str, 'lat_bin': float, 'lon_bin': float, 'captured_at': str, 'sequence': str, 'country': str, 'thumb_original_url': str, 'longitude': float, 'latitude': float
80
+ })
81
+ if not self.full:
82
+ df = df[['id', 'latitude', 'longitude', 'country', 'region', 'sub-region', 'city']]
83
+
84
+ df = df.set_index('id')
85
+ self.df_[annotation_path] = df.to_dict('index')
86
+ return self.df_[annotation_path]
87
+
88
+ def _split_generators(self, dl_manager):
89
+ _URLS = {
90
+ "train": [join('images', 'train', str(i).zfill(2) + '.zip') for i in range(98)],
91
+ "test": [join('images', 'test', str(i).zfill(2) + '.zip') for i in range(5)],
92
+ "train_meta": "train.csv",
93
+ "test_meta": "test.csv",
94
+ }
95
+
96
+ data_files = dl_manager.download_and_extract(_URLS)
97
+ return [
98
+ datasets.SplitGenerator(
99
+ name=datasets.Split.TRAIN,
100
+ gen_kwargs={
101
+ "image_paths": dl_manager.iter_files(data_files["train"]),
102
+ "annotation_path": data_files["train_meta"],
103
+ },
104
+ ),
105
+ datasets.SplitGenerator(
106
+ name=datasets.Split.TEST,
107
+ gen_kwargs={
108
+ "image_paths": dl_manager.iter_files(data_files["test"]),
109
+ "annotation_path": data_files["test_meta"],
110
+ },
111
+ ),
112
+ ]
113
+
114
+ def _generate_examples(self, image_paths, annotation_path):
115
+ """Generate examples."""
116
+ df = self.df(annotation_path)
117
+ for idx, image_path in enumerate(image_paths):
118
+ info_id = os.path.splitext(os.path.split(image_path)[-1])[0]
119
+ try:
120
+ example = {
121
+ "image": image_path,
122
+ } | df[info_id]
123
+ except Exception as e:
124
+ print('Exception ' + str(e), info_id, idx, image_path, sep='\n')
125
+ continue
126
+
127
+ yield idx, example