mathiaszinnen commited on
Commit
982ece5
·
1 Parent(s): 072eda4

Get metadata csv from zenodo

Browse files
Files changed (1) hide show
  1. odor.py +13 -5
odor.py CHANGED
@@ -31,6 +31,7 @@ _HOMEPAGE = "https://zenodo.org/record/10027116"
31
 
32
  _LICENSE = "CC BY 4.0"
33
 
 
34
 
35
  _CATEGORIES = ['ant', 'camel', 'jewellery', 'frog', 'physalis', 'celery', 'cauliflower', 'pepper', 'ranunculus', 'chess flower', 'cigarette', 'matthiola', 'cabbage', 'earring', 'dandelion', 'neroli', 'dragonfly', 'hyacinth', 'reptile/amphibia', 'apricot', 'snake', 'lizard', 'asparagus', 'spring onion', 'snowflake', 'moth', 'poppy', 'columbine', 'rabbit', 'geranium', 'crab', 'radish', 'big cat', 'jan steen jug', 'monkey', 'snail', 'bellflower', 'lilac', 'pot', 'peony', 'coffeepot', 'hazelnut', 'censer', 'artichoke', 'dahlia', 'sniffing', 'fly', 'deer', 'caterpillar', 'garlic', 'blackberry', 'chalice', 'lobster', 'necklace', 'bug', 'insect', 'prawn', 'bracelet', 'carrot', 'cornflower', 'pumpkin', 'orange', 'walnut', 'cat', 'daisy', 'forget-me-not', 'carafe', 'match', 'beer stein', 'tobacco-box', 'violet', 'pomander', 'bottle', 'candle', 'heliotrope', 'wine bottle', 'strawberry', 'pomegranate', 'whale', 'lily of the valley', 'iris', 'tobacco', 'olive', 'tobacco-packaging', 'meat', 'daffodil', 'melon', 'fire', 'petunia', 'mushroom', 'teapot', 'ring', 'pig', 'ashtray', 'cheese', 'onion', 'cup', 'nut', 'fig', 'drinking vessel', 'donkey', 'holding the nose', 'lily', 'smoke', 'bread', 'currant', 'glass without stem', 'anemone', 'mammal', 'chimney', 'smoking equipment', 'bivalve', 'butterfly', 'gloves', 'lemon', 'horse', 'plum', 'jasmine', 'pear', 'glass with stem', 'vegetable', 'carnation', 'jug', 'goat', 'fish', 'apple', 'tulip', 'cherry', 'cow', 'animal corpse', 'dog', 'fruit', 'bird', 'rose', 'peach', 'sheep', 'pipe', 'grapes', 'flower']
36
 
@@ -66,10 +67,10 @@ class ODOR(datasets.GeneratorBasedBuilder):
66
  )
67
 
68
  def _split_generators(self, dl_manager):
69
- def _download_one(entry, overwrite=False):
70
- fn, uri, target_pth, retries = entry
71
- fn = fn.replace("/", "_")
72
  path = f'{target_pth}/{fn}'
 
73
  if os.path.exists(path) and not overwrite:
74
  return fn
75
 
@@ -88,8 +89,14 @@ class ODOR(datasets.GeneratorBasedBuilder):
88
  else:
89
  time.sleep(i)
90
  continue
91
-
92
  return fn
 
 
 
 
 
 
 
93
  def _download_all(metadata_pth, target_pth, retries=3):
94
  df = pd.read_csv(metadata_pth)
95
  entries = [[*x, target_pth, retries] for x in df[['File Name', 'Image Credits']].values]
@@ -99,9 +106,10 @@ class ODOR(datasets.GeneratorBasedBuilder):
99
  return results
100
 
101
  imgs_dir = f'{self.cache_dir}/images'
102
- csv_pth = f'{self.cache_dir}/meta/meta.csv'
103
  if not os.path.isdir(imgs_dir):
104
  os.makedirs(imgs_dir)
 
105
  img_pths = _download_all(csv_pth, imgs_dir)
106
 
107
  return [
 
31
 
32
  _LICENSE = "CC BY 4.0"
33
 
34
+ _META_URL = 'https://zenodo.org/records/10027116/files/meta.csv?download=1'
35
 
36
  _CATEGORIES = ['ant', 'camel', 'jewellery', 'frog', 'physalis', 'celery', 'cauliflower', 'pepper', 'ranunculus', 'chess flower', 'cigarette', 'matthiola', 'cabbage', 'earring', 'dandelion', 'neroli', 'dragonfly', 'hyacinth', 'reptile/amphibia', 'apricot', 'snake', 'lizard', 'asparagus', 'spring onion', 'snowflake', 'moth', 'poppy', 'columbine', 'rabbit', 'geranium', 'crab', 'radish', 'big cat', 'jan steen jug', 'monkey', 'snail', 'bellflower', 'lilac', 'pot', 'peony', 'coffeepot', 'hazelnut', 'censer', 'artichoke', 'dahlia', 'sniffing', 'fly', 'deer', 'caterpillar', 'garlic', 'blackberry', 'chalice', 'lobster', 'necklace', 'bug', 'insect', 'prawn', 'bracelet', 'carrot', 'cornflower', 'pumpkin', 'orange', 'walnut', 'cat', 'daisy', 'forget-me-not', 'carafe', 'match', 'beer stein', 'tobacco-box', 'violet', 'pomander', 'bottle', 'candle', 'heliotrope', 'wine bottle', 'strawberry', 'pomegranate', 'whale', 'lily of the valley', 'iris', 'tobacco', 'olive', 'tobacco-packaging', 'meat', 'daffodil', 'melon', 'fire', 'petunia', 'mushroom', 'teapot', 'ring', 'pig', 'ashtray', 'cheese', 'onion', 'cup', 'nut', 'fig', 'drinking vessel', 'donkey', 'holding the nose', 'lily', 'smoke', 'bread', 'currant', 'glass without stem', 'anemone', 'mammal', 'chimney', 'smoking equipment', 'bivalve', 'butterfly', 'gloves', 'lemon', 'horse', 'plum', 'jasmine', 'pear', 'glass with stem', 'vegetable', 'carnation', 'jug', 'goat', 'fish', 'apple', 'tulip', 'cherry', 'cow', 'animal corpse', 'dog', 'fruit', 'bird', 'rose', 'peach', 'sheep', 'pipe', 'grapes', 'flower']
37
 
 
67
  )
68
 
69
  def _split_generators(self, dl_manager):
70
+
71
+ def _download_file(uri, target_pth, fn, retries, overwrite=False):
 
72
  path = f'{target_pth}/{fn}'
73
+
74
  if os.path.exists(path) and not overwrite:
75
  return fn
76
 
 
89
  else:
90
  time.sleep(i)
91
  continue
 
92
  return fn
93
+
94
+ def _download_one(entry, overwrite=False):
95
+ fn, uri, target_pth, retries = entry
96
+ fn = fn.replace("/", "_")
97
+
98
+ return _download_file(uri, target_pth, fn, retries, overwrite)
99
+
100
  def _download_all(metadata_pth, target_pth, retries=3):
101
  df = pd.read_csv(metadata_pth)
102
  entries = [[*x, target_pth, retries] for x in df[['File Name', 'Image Credits']].values]
 
106
  return results
107
 
108
  imgs_dir = f'{self.cache_dir}/images'
109
+ csv_pth = _download_file(_META_URL, f'{self.cache_dir}', 'meta.csv', 3)
110
  if not os.path.isdir(imgs_dir):
111
  os.makedirs(imgs_dir)
112
+
113
  img_pths = _download_all(csv_pth, imgs_dir)
114
 
115
  return [