Update soybean_dataset.py
Browse files- soybean_dataset.py +15 -20
soybean_dataset.py
CHANGED
@@ -21,10 +21,10 @@ import os
|
|
21 |
from typing import List
|
22 |
import datasets
|
23 |
import logging
|
24 |
-
|
25 |
import numpy as np
|
26 |
from PIL import Image
|
27 |
-
|
28 |
import io
|
29 |
import pandas as pd
|
30 |
import matplotlib.pyplot as plt
|
@@ -87,15 +87,15 @@ class SoybeanDataset(datasets.GeneratorBasedBuilder):
|
|
87 |
{
|
88 |
"unique_id": datasets.Value("string"),
|
89 |
"sets": datasets.Value("string"),
|
90 |
-
"original_image": datasets.
|
91 |
-
"segmentation_image": datasets.
|
92 |
|
93 |
}
|
94 |
),
|
95 |
# No default supervised_keys (as we have to pass both question
|
96 |
# and context as input).
|
97 |
supervised_keys=("original_image","segmentation_image"),
|
98 |
-
|
99 |
citation=_CITATION,
|
100 |
)
|
101 |
|
@@ -118,15 +118,12 @@ class SoybeanDataset(datasets.GeneratorBasedBuilder):
|
|
118 |
]
|
119 |
|
120 |
def process_image(self,image_url):
|
121 |
-
|
122 |
-
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
numpydata = asarray(img)
|
128 |
-
|
129 |
-
return numpydata
|
130 |
|
131 |
|
132 |
|
@@ -145,8 +142,8 @@ class SoybeanDataset(datasets.GeneratorBasedBuilder):
|
|
145 |
segmentation_image_path = row['segmentation_image']
|
146 |
sets = row['sets']
|
147 |
|
148 |
-
|
149 |
-
|
150 |
|
151 |
|
152 |
# Here you need to replace 'initial_radius', 'final_radius', 'initial_angle', 'final_angle', 'target'
|
@@ -154,8 +151,8 @@ class SoybeanDataset(datasets.GeneratorBasedBuilder):
|
|
154 |
yield row['unique_id'], {
|
155 |
"unique_id": unique_id,
|
156 |
"sets": sets,
|
157 |
-
"original_image":
|
158 |
-
"segmentation_image":
|
159 |
# ... add other features if necessary
|
160 |
}
|
161 |
|
@@ -189,6 +186,4 @@ class SoybeanDataset(datasets.GeneratorBasedBuilder):
|
|
189 |
|
190 |
|
191 |
|
192 |
-
|
193 |
-
|
194 |
-
|
|
|
21 |
from typing import List
|
22 |
import datasets
|
23 |
import logging
|
24 |
+
import csv
|
25 |
import numpy as np
|
26 |
from PIL import Image
|
27 |
+
import os
|
28 |
import io
|
29 |
import pandas as pd
|
30 |
import matplotlib.pyplot as plt
|
|
|
87 |
{
|
88 |
"unique_id": datasets.Value("string"),
|
89 |
"sets": datasets.Value("string"),
|
90 |
+
"original_image": datasets.Image(),
|
91 |
+
"segmentation_image": datasets.Image(),
|
92 |
|
93 |
}
|
94 |
),
|
95 |
# No default supervised_keys (as we have to pass both question
|
96 |
# and context as input).
|
97 |
supervised_keys=("original_image","segmentation_image"),
|
98 |
+
homepage="https://github.com/lisawen0707/soybean/tree/main",
|
99 |
citation=_CITATION,
|
100 |
)
|
101 |
|
|
|
118 |
]
|
119 |
|
120 |
def process_image(self,image_url):
|
121 |
+
response = requests.get(image_url)
|
122 |
+
response.raise_for_status() # This will raise an exception if there is a download error
|
123 |
|
124 |
+
# Open the image from the downloaded bytes and return the PIL Image
|
125 |
+
img = Image.open(BytesIO(response.content))
|
126 |
+
return img
|
|
|
|
|
|
|
127 |
|
128 |
|
129 |
|
|
|
142 |
segmentation_image_path = row['segmentation_image']
|
143 |
sets = row['sets']
|
144 |
|
145 |
+
original_image = self.process_image(original_image_path)
|
146 |
+
segmentation_image = self.process_image(segmentation_image_path)
|
147 |
|
148 |
|
149 |
# Here you need to replace 'initial_radius', 'final_radius', 'initial_angle', 'final_angle', 'target'
|
|
|
151 |
yield row['unique_id'], {
|
152 |
"unique_id": unique_id,
|
153 |
"sets": sets,
|
154 |
+
"original_image": original_image,
|
155 |
+
"segmentation_image": segmentation_image,
|
156 |
# ... add other features if necessary
|
157 |
}
|
158 |
|
|
|
186 |
|
187 |
|
188 |
|
189 |
+
|
|
|
|