Update mhr_recognize_datasets.py
Browse files- mhr_recognize_datasets.py +17 -1
mhr_recognize_datasets.py
CHANGED
|
@@ -63,4 +63,20 @@ class MHRRecognizeDatasets(datasets.GeneratorBasedBuilder):
|
|
| 63 |
for idx, row in metadata_df.iterrows():
|
| 64 |
image_path = Path(image_dir) / row["file_name"]
|
| 65 |
sample_dict = {'image': str(image_path), 'label': row}
|
| 66 |
-
yield idx, sample_dict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
for idx, row in metadata_df.iterrows():
|
| 64 |
image_path = Path(image_dir) / row["file_name"]
|
| 65 |
sample_dict = {'image': str(image_path), 'label': row}
|
| 66 |
+
yield idx, sample_dict
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def _generate_examples(self, files):
|
| 70 |
+
|
| 71 |
+
if self.config.name == "whole_image":
|
| 72 |
+
# Read csv with image labels
|
| 73 |
+
label_csv = read_csv(_DATA_URL["labels"])
|
| 74 |
+
for i, path in enumerate(files):
|
| 75 |
+
file_name = os.path.basename(path)
|
| 76 |
+
# Get image id to filter the respective row of the csv
|
| 77 |
+
image_id = file_name
|
| 78 |
+
image_labels = label_csv[label_csv["name"] == image_id]["label"]
|
| 79 |
+
yield i, {
|
| 80 |
+
"image": path,
|
| 81 |
+
"labels": image_labels,
|
| 82 |
+
}
|