lisawen commited on
Commit
6f462b4
1 Parent(s): 7ca70ae

Update soybean_dataset.py

Browse files
Files changed (1) hide show
  1. soybean_dataset.py +12 -3
soybean_dataset.py CHANGED
@@ -34,6 +34,7 @@ from io import BytesIO
34
  from numpy import asarray
35
  from concurrent.futures import ThreadPoolExecutor, as_completed
36
  import requests
 
37
 
38
  import logging
39
 
@@ -120,12 +121,20 @@ class SoybeanDataset(datasets.GeneratorBasedBuilder):
120
  datasets.SplitGenerator(
121
  name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["valid"]}),
122
  ]
 
 
 
 
123
 
 
 
 
 
124
 
 
125
  def process_image(self,image_url):
126
- response = requests.get(image_url)
127
- response.raise_for_status() # This will raise an exception if there is a download error
128
-
129
  # Open the image from the downloaded bytes and return the PIL Image
130
  img = Image.open(BytesIO(response.content))
131
  return img
 
34
  from numpy import asarray
35
  from concurrent.futures import ThreadPoolExecutor, as_completed
36
  import requests
37
+ import asyncio
38
 
39
  import logging
40
 
 
121
  datasets.SplitGenerator(
122
  name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["valid"]}),
123
  ]
124
+ def background(f):
125
+ def wrapped(*args, **kwargs):
126
+ return asyncio.get_event_loop().run_in_executor(None, f, *args, **kwargs)
127
+ return wrapped
128
 
129
+ @background
130
+ def download(url, fn):
131
+ r = requests.get(url)
132
+
133
 
134
+
135
  def process_image(self,image_url):
136
+ response = download(image_url)
137
+
 
138
  # Open the image from the downloaded bytes and return the PIL Image
139
  img = Image.open(BytesIO(response.content))
140
  return img