Skip to content

Commit 06730f3

Browse files
authored
Merge pull request #10 from Project-AgML/dev
Release 0.2.5
2 parents 25baab9 + 460b7fd commit 06730f3

File tree

5 files changed

+261
-1
lines changed

5 files changed

+261
-1
lines changed

agml/_assets/public_datasources.json

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,5 +799,98 @@
799799
0.20582404732704163
800800
]
801801
}
802+
},
803+
"guava_disease_pakistan": {
804+
"classes": {
805+
"1": "Canker",
806+
"2": "Dot",
807+
"3": "Mummification",
808+
"4": "Rust"
809+
},
810+
"ml_task": "image_classification",
811+
"ag_task": "disease_classification",
812+
"location": {
813+
"continent": "asia",
814+
"country": "pakistan"
815+
},
816+
"sensor_modality": "rgb",
817+
"platform": "ground",
818+
"input_data_format": "jpg",
819+
"annotation_format": "directory_names",
820+
"n_images": "306",
821+
"docs_url": "https://data.mendeley.com/datasets/s8x6jn5cvr/1",
822+
"external_image_sources": [],
823+
"stats": {
824+
"mean": [
825+
0.44554805755615234,
826+
0.4508753716945648,
827+
0.3228892683982849
828+
],
829+
"std": [
830+
0.18661099672317505,
831+
0.18359656631946564,
832+
0.18744423985481262
833+
]
834+
}
835+
},
836+
"apple_detection_spain": {
837+
"classes": {
838+
"1": "apple"
839+
},
840+
"ml_task": "object_detection",
841+
"ag_task": "fruit_detection",
842+
"location": {
843+
"continent": "europe",
844+
"country": "spain"
845+
},
846+
"sensor_modality": "rgb",
847+
"platform": "ground",
848+
"input_data_format": "jpg",
849+
"annotation_format": "coco_json",
850+
"n_images": "967",
851+
"docs_url": "https://www.grap.udl.cat/en/publications/KFuji_RGBDS_database.html",
852+
"external_image_sources": [],
853+
"stats": {
854+
"mean": [
855+
0.3745550215244293,
856+
0.4699203670024872,
857+
0.3931747078895569
858+
],
859+
"std": [
860+
0.2724320888519287,
861+
0.27973315119743347,
862+
0.2829023003578186
863+
]
864+
}
865+
},
866+
"apple_detection_drone_brazil": {
867+
"classes": {
868+
"1": "apple"
869+
},
870+
"ml_task": "object_detection",
871+
"ag_task": "fruit_detection",
872+
"location": {
873+
"continent": "south_america",
874+
"country": "brazil"
875+
},
876+
"sensor_modality": "rgb",
877+
"platform": "ground",
878+
"input_data_format": "jpg",
879+
"annotation_format": "coco_json",
880+
"n_images": "689",
881+
"docs_url": "https://github.com/thsant/add256/tree/zenodo-1.0",
882+
"external_image_sources": [],
883+
"stats": {
884+
"mean": [
885+
0.3362397849559784,
886+
0.48177945613861084,
887+
0.32026395201683044
888+
],
889+
"std": [
890+
0.18435567617416382,
891+
0.1873108297586441,
892+
0.1734534204006195
893+
]
894+
}
802895
}
803896
}

agml/_assets/shape_info.pickle

479 Bytes
Binary file not shown.

agml/_assets/source_citations.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,17 @@
8686
"grape_detection_californianight": {
8787
"license": "",
8888
"citation": "@misc{GrapeNight,\n author = {Plant AI and Biophysics Lab},\n title = {Grape Detection 2020 Night},\n year = {2020},\n url = {https://github.com/plant-ai-biophysics-lab/AgML} \n "
89+
},
90+
"guava_disease_pakistan": {
91+
"license": "",
92+
"citation": "@article{Rauf_Lali_2021, \n title={A Guava Fruits and Leaves Dataset for Detection and Classification of Guava Diseases through Machine Learning}, \n volume={1}, \n url={https://data.mendeley.com/datasets/s8x6jn5cvr/1}, \n DOI={10.17632/s8x6jn5cvr.1}, \n abstractNote={(1) Plant diseases are the primary cause of reduced productivity in agriculture, which results in economic losses. Guava is a big source of nutrients for humans all over the world. Guava diseases, on the other hand, harm the yield and quality of the crop. (2) For the identification and classification of plant diseases, computer vision and image processing methods have been commonly used. (3) The dataset includes an image gallery of healthy and unhealthy Guava fruits and leaves that could be used by researchers to adopt advanced computer vision techniques to protect plants from disease. Dot, Canker, Mummification, and Rust are the diseases targeted in the data sets. (4) The dataset contains 306 images of healthy and unhealthy images for both Guava fruits and leaves collectively. Each image contains 6000 * 4000 dimensions with 300 dpi resolution. (5) All images were acquired from the tropical areas of Pakistan under the supervision of Prof. Dr. Ikramullah Lali. (6) All images were annotated manually by the domain expert such as For Guava fruits and leaves; Dot (76), Canker (77), Mummification (83), and Rust (70) Note: The data labeling was manual and can be updated by automatic labeling through machine learning. In the meantime, the authors can also use the data set for the clustering problem.}, \n author={Rauf, Hafiz Tayyab and Lali, Muhammad Ikram Ullah}, \n year={2021}, month={Apr} \n}\n"
93+
},
94+
"apple_detection_spain": {
95+
"license": "",
96+
"citation": "@article{GENEMOLA2019104289,\ntitle = {KFuji RGB-DS database: Fuji apple multi-modal images for fruit detection with color, depth and range-corrected IR data},\njournal = {Data in Brief},\nvolume = {25},\npages = {104289},\nyear = {2019},\nissn = {2352-3409},\ndoi = {https://doi.org/10.1016/j.dib.2019.104289},\nurl = {https://www.sciencedirect.com/science/article/pii/S2352340919306432},\nauthor = {Jordi Gené-Mola and Verónica Vilaplana and Joan R. Rosell-Polo and Josep-Ramon Morros and Javier Ruiz-Hidalgo and Eduard Gregorio},\nkeywords = {Multi-modal dataset, Fruit detection, Depth cameras, RGB-D, Fruit reflectance, Fuji apple},\nabstract = {This article contains data related to the research article entitle “Multi-modal Deep Learning for Fruit Detection Using RGB-D Cameras and their Radiometric Capabilities” [1]. The development of reliable fruit detection and localization systems is essential for future sustainable agronomic management of high-value crops. RGB-D sensors have shown potential for fruit detection and localization since they provide 3D information with color data. However, the lack of substantial datasets is a barrier for exploiting the use of these sensors. This article presents the KFuji RGB-DS database which is composed by 967 multi-modal images of Fuji apples on trees captured using Microsoft Kinect v2 (Microsoft, Redmond, WA, USA). Each image contains information from 3 different modalities: color (RGB), depth (D) and range corrected IR intensity (S). Ground truth fruit locations were manually annotated, labeling a total of 12,839 apples in all the dataset. The current dataset is publicly available at http://www.grap.udl.cat/publicacions/datasets.html.}\n}"
97+
},
98+
"apple_detection_drone_brazil": {
99+
"license": "CC BY-SA 4.0",
100+
"citation": "@article{DBLP:journals/corr/abs-2110-12331,\n author = {Thiago T. Santos and\n Luciano Gebler},\n title = {A methodology for detection and localization of fruits in apples orchards\n from aerial images},\n journal = {CoRR},\n volume = {abs/2110.12331},\n year = {2021},\n url = {https://arxiv.org/abs/2110.12331},\n eprinttype = {arXiv},\n eprint = {2110.12331},\n timestamp = {Thu, 28 Oct 2021 15:25:31 +0200},\n biburl = {https://dblp.org/rec/journals/corr/abs-2110-12331.bib},\n bibsource = {dblp computer science bibliography, https://dblp.org}\n}"
89101
}
90102
}

agml/_internal/preprocess.py

Lines changed: 155 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def cotton_seedling_counting(self, dataset_name):
380380
if path not in valid_paths:
381381
continue
382382
shutil.copyfile(path, os.path.join(processed_img_dir, os.path.basename(path)))
383-
with open(os.path.join(processed_dir, 'labels.json'), 'w') as f:
383+
with open(os.path.join(processed_dir, 'annotations.json'), 'w') as f:
384384
json.dump(all_annotation_data, f, indent = 4)
385385

386386
# Zip the dataset
@@ -573,5 +573,159 @@ def autonomous_greenhouse_regression(self, dataset_name):
573573
# Save the annotation file.
574574
with open(os.path.join(out_dir, 'annotations.json'), 'w') as f:
575575
json.dump(out, f)
576+
577+
def guava_disease_pakistan(self, dataset_name):
578+
# Get all of the images.
579+
dataset_dir = os.path.join(self.data_original_dir, dataset_name)
580+
classes = os.listdir(dataset_dir)
581+
all_images = []
582+
for cls in classes:
583+
all_images.extend([
584+
os.path.join(dataset_dir, cls, i)
585+
for i in os.listdir(os.path.join(dataset_dir, cls))])
586+
587+
# Resize all of the images.
588+
out_dir = os.path.join(self.data_processed_dir, dataset_name)
589+
os.makedirs(out_dir, exist_ok = True)
590+
for cls in classes:
591+
os.makedirs(os.path.join(out_dir, cls), exist_ok = True)
592+
for image in tqdm(all_images, 'Resizing Images'):
593+
out_image = image.replace('/original/', '/processed/')
594+
im = cv2.imread(image, cv2.IMREAD_UNCHANGED)
595+
im = cv2.resize(im, (im.shape[1] // 5, im.shape[0] // 5), cv2.INTER_LINEAR)
596+
cv2.imwrite(out_image, im)
597+
598+
def apple_detection_spain(self, dataset_name):
599+
# resize the dataset
600+
resize = 1.0
601+
602+
# Read public_datasources.json to get class information
603+
datasource_file = os.path.join(os.path.dirname(__file__), "../_assets/public_datasources.json")
604+
with open(datasource_file) as f:
605+
data = json.load(f)
606+
category_info = data[dataset_name]['crop_types']
607+
labels_str = []
608+
labels_ids = []
609+
for info in category_info:
610+
labels_str.append(category_info[info])
611+
labels_ids.append(int(info))
612+
613+
name_converter = dict(zip(["Poma"], ["apple"])) # src -> dst
614+
label2id = dict(zip(labels_str, labels_ids))
615+
616+
dataset_dir = os.path.join(self.data_original_dir, dataset_name)
617+
ann_dir = os.path.join(dataset_dir, "preprocessed data/square_annotations1")
618+
619+
# Get image file and xml file
620+
all_files = get_file_list(ann_dir)
621+
anno_files = [os.path.join(ann_dir, x) for x in all_files if "xml" in x]
622+
img_files = [x.replace(".xml", "hr.jpg").replace("square_annotations1", "images") for x in anno_files]
623+
624+
# Process annotation files
625+
save_dir_anno = os.path.join(self.data_processed_dir, dataset_name, 'annotations')
626+
create_dir(save_dir_anno)
627+
output_json_file = os.path.join(save_dir_anno, 'instances.json')
628+
629+
# Process image files
630+
output_img_path = os.path.join(self.data_processed_dir, dataset_name, 'images')
631+
create_dir(output_img_path)
632+
633+
general_info = {
634+
"description": "KFuji RGB-DS database",
635+
"url": "http://www.grap.udl.cat/en/publications/KFuji_RGBDS_database.html",
636+
"version": "1.0",
637+
"year": 2018,
638+
"contributor": "Gené-Mola J, Vilaplana V, Rosell-Polo JR, Morros JR, Ruiz-Hidalgo J, Gregorio E",
639+
"date_created": "2018/10/19"
640+
}
641+
642+
convert_xmls_to_cocojson(
643+
general_info,
644+
annotation_paths = anno_files,
645+
img_paths = img_files,
646+
label2id = label2id,
647+
name_converter = name_converter,
648+
output_jsonpath = output_json_file,
649+
output_imgpath = output_img_path,
650+
extract_num_from_imgid = True
651+
)
652+
653+
def apple_detection_drone_brazil(self, dataset_name):
654+
# Get the data directory and rename it if necessary.
655+
dataset_dir = os.path.join(self.data_original_dir, dataset_name)
656+
if not os.path.exists(dataset_dir):
657+
fallback = os.path.join(self.data_original_dir,
658+
'thsant-add256-68d2f88') # noqa
659+
if os.path.exists(fallback):
660+
os.rename(fallback, dataset_dir)
661+
662+
# Get all of the images which have valid annotations.
663+
with open(os.path.join(dataset_dir, 'all.json'), 'r') as f:
664+
original_annotations = json.load(f)
665+
valid_annotations = {k: v for k, v in
666+
original_annotations.items() if v != []}
667+
668+
# Construct the `images` part of the COCO JSON.
669+
image_coco = []
670+
image_id_map = {}
671+
image_dir = os.path.join(dataset_dir, 'images')
672+
for idx, image_name in tqdm(
673+
enumerate(valid_annotations.keys()),
674+
desc = "Parsing Images", total = len(valid_annotations)):
675+
height, width = cv2.imread(os.path.join(image_dir, image_name)).shape[:2]
676+
image_coco.append(
677+
{'file_name': image_name, 'height': height,
678+
'width': width, 'id': idx})
679+
image_id_map[image_name] = idx
680+
681+
# Construct the `annotations` part of the COCO JSON.
682+
annotation_idx = 0
683+
annotation_coco = []
684+
for image_name, annotation_list in valid_annotations.items():
685+
for annotation in annotation_list:
686+
# Coordinates are in form (center_x, center_y, radius). We convert
687+
# these to (top left x, top left y, width, height)
688+
x_c, y_c, r = annotation['cx'], annotation['cy'], annotation['r']
689+
x, y = x_c - r, y_c - r
690+
w = h = r * 2
691+
annotation_coco.append({
692+
'area': w * h, 'iscrowd': 0, 'bbox': [x, y, w, h],
693+
'category_id': 1, 'ignore': 0, 'segmentation': 0,
694+
'image_id': image_id_map[image_name], 'id': annotation_idx})
695+
annotation_idx += 1
696+
697+
# Set up the annotation dictionary.
698+
category_info = [{'supercategory': 'none', 'id': 1, 'name': 'apple'}]
699+
all_annotation_data = {
700+
"images": image_coco, "type": "instances",
701+
"annotations": annotation_coco, "categories": category_info,
702+
"info": {
703+
"description": "apple detection dataset with drone imagery",
704+
"url": "https://github.com/thsant/add256/tree/zenodo-1.0",
705+
"version": "1.0",
706+
"year": 2021,
707+
"contributor": "Thiago T. Santos and Luciano Gebler",
708+
"date_created": "2021/10/2021"
709+
}
710+
}
711+
712+
# Recreate the dataset and zip it
713+
processed_dir = os.path.join(self.data_processed_dir, dataset_name)
714+
processed_img_dir = os.path.join(processed_dir, 'images')
715+
if os.path.exists(processed_dir):
716+
shutil.rmtree(processed_dir)
717+
os.makedirs(processed_dir, exist_ok = True)
718+
os.makedirs(processed_img_dir, exist_ok = True)
719+
for path in tqdm(valid_annotations.keys(), desc = "Moving Images"):
720+
full_path = os.path.join(image_dir, path)
721+
shutil.copyfile(full_path, os.path.join(
722+
processed_img_dir, os.path.basename(path)))
723+
with open(os.path.join(processed_dir, 'annotations.json'), 'w') as f:
724+
json.dump(all_annotation_data, f)
725+
726+
727+
728+
576729

730+
PublicDataPreprocessor('../../data_new').preprocess('apple_detection_drone_brazil')
577731

agml/data/builder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def from_data(cls, contents, info, root):
6565
obj._info_map = info.class_to_num
6666
obj._dataset_root = root
6767
obj._data = contents
68+
obj._external_image_sources = info.external_image_sources
6869
return obj
6970

7071
@property

0 commit comments

Comments
 (0)