Yuhan Hou
commited on
Commit
•
cee7b91
1
Parent(s):
f3fb371
My commit
Browse files- FracAtlas_dataset.py +16 -17
FracAtlas_dataset.py
CHANGED
@@ -92,20 +92,19 @@ class FracAtlasDataset(datasets.GeneratorBasedBuilder):
|
|
92 |
features=datasets.Features(
|
93 |
{
|
94 |
"image_id": datasets.Value("string"),
|
95 |
-
#"image_path": datasets.Value("string"),
|
96 |
"image": datasets.Image(),
|
97 |
-
"hand": datasets.ClassLabel(num_classes=2,names=['
|
98 |
-
"leg":datasets.
|
99 |
-
"hip": datasets.
|
100 |
-
"shoulder": datasets.
|
101 |
-
"mixed": datasets.
|
102 |
-
"hardware": datasets.
|
103 |
-
"multiscan": datasets.
|
104 |
-
"fractured": datasets.
|
105 |
"fracture_count": datasets.Value("int32"),
|
106 |
-
"frontal": datasets.
|
107 |
-
"lateral": datasets.
|
108 |
-
"oblique": datasets.
|
109 |
"localization_metadata": datasets.Features({
|
110 |
"width": datasets.Value("int32"),
|
111 |
"height": datasets.Value("int32"),
|
@@ -204,13 +203,14 @@ class FracAtlasDataset(datasets.GeneratorBasedBuilder):
|
|
204 |
annotation = annotations.get(image_id)
|
205 |
image_path = os.path.join(images_path, folder, image_id)
|
206 |
|
|
|
207 |
segmentation, bbox, area = None, None, None
|
208 |
segmentation_metadata = None
|
209 |
|
210 |
if annotation:
|
211 |
-
segmentation = annotation.get('segmentation')
|
212 |
-
bbox = annotation.get('bbox')
|
213 |
-
area = annotation.get('area')
|
214 |
|
215 |
segmentation_metadata = {
|
216 |
'segmentation': segmentation,
|
@@ -218,7 +218,7 @@ class FracAtlasDataset(datasets.GeneratorBasedBuilder):
|
|
218 |
'area': area
|
219 |
}
|
220 |
else:
|
221 |
-
segmentation_metadata = None
|
222 |
|
223 |
xml_file_name = f"{image_id.split('.')[0]}.xml"
|
224 |
xml_path = os.path.join(localization_path, xml_file_name)
|
@@ -236,7 +236,6 @@ class FracAtlasDataset(datasets.GeneratorBasedBuilder):
|
|
236 |
# Construct example data
|
237 |
example_data = {
|
238 |
"image_id": row['image_id'],
|
239 |
-
#"image_path": image_path,
|
240 |
"image":image_path,
|
241 |
"hand": row["hand"],
|
242 |
"leg": row["leg"],
|
|
|
92 |
features=datasets.Features(
|
93 |
{
|
94 |
"image_id": datasets.Value("string"),
|
|
|
95 |
"image": datasets.Image(),
|
96 |
+
"hand": datasets.ClassLabel(num_classes=2,names=['no_hand_fracture','hand_fracture']),
|
97 |
+
"leg": datasets.ClassLabel(num_classes=2,names=['no_leg_fracture','leg_fracture']),
|
98 |
+
"hip": datasets.ClassLabel(num_classes=2,names=['no_hip_fracture','hip_fracture']),
|
99 |
+
"shoulder": datasets.ClassLabel(num_classes=2,names=['no_shoulder_fracture','shoulder_fracture']),
|
100 |
+
"mixed": datasets.ClassLabel(num_classes=2,names=['not_mixed','mixed']),
|
101 |
+
"hardware": datasets.ClassLabel(num_classes=2,names=['no_hardware','hardware']),
|
102 |
+
"multiscan": datasets.ClassLabel(num_classes=2,names=['not_multiscan','multiscan']),
|
103 |
+
"fractured": datasets.ClassLabel(num_classes=2,names=['not_fractured','fractured']),
|
104 |
"fracture_count": datasets.Value("int32"),
|
105 |
+
"frontal": datasets.ClassLabel(num_classes=2,names=['not_frontal','frontal']),
|
106 |
+
"lateral": datasets.ClassLabel(num_classes=2,names=['not_lateral','lateral']),
|
107 |
+
"oblique": datasets.ClassLabel(num_classes=2,names=['not_oblique','oblique']),
|
108 |
"localization_metadata": datasets.Features({
|
109 |
"width": datasets.Value("int32"),
|
110 |
"height": datasets.Value("int32"),
|
|
|
203 |
annotation = annotations.get(image_id)
|
204 |
image_path = os.path.join(images_path, folder, image_id)
|
205 |
|
206 |
+
# Initialize variables
|
207 |
segmentation, bbox, area = None, None, None
|
208 |
segmentation_metadata = None
|
209 |
|
210 |
if annotation:
|
211 |
+
segmentation = annotation.get('segmentation')
|
212 |
+
bbox = annotation.get('bbox')
|
213 |
+
area = annotation.get('area')
|
214 |
|
215 |
segmentation_metadata = {
|
216 |
'segmentation': segmentation,
|
|
|
218 |
'area': area
|
219 |
}
|
220 |
else:
|
221 |
+
segmentation_metadata = None # Default if not present
|
222 |
|
223 |
xml_file_name = f"{image_id.split('.')[0]}.xml"
|
224 |
xml_path = os.path.join(localization_path, xml_file_name)
|
|
|
236 |
# Construct example data
|
237 |
example_data = {
|
238 |
"image_id": row['image_id'],
|
|
|
239 |
"image":image_path,
|
240 |
"hand": row["hand"],
|
241 |
"leg": row["leg"],
|