sc890 commited on
Commit
736d93a
1 Parent(s): f40ad88

Upload 3 files

Browse files
Fruits_Dataset_Test.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b3d1b7134ee6d3a80415f621525c0fc7e02acef577addbade11c0207ac0298e0
3
+ size 31193754
Fruits_Dataset_Train.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6d17131f7594d2aa242a29f111253fdb87f329bd6bdd4451f3a890c8382ffa71
3
+ size 124589013
deepfruit_dataset.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # TODO: Address all TODOs and remove all explanatory comments
15
+ """TODO: Add a description here."""
16
+
17
+
18
+ import csv
19
+ import json
20
+ from PIL import Image as IMG
21
+ import os
22
+ import datasets
23
+ import pandas as pd
24
+
25
+ from datasets import GeneratorBasedBuilder, DatasetInfo, Features, ClassLabel,Image, SplitGenerator, Sequence
26
+
27
+ _DESCRIPTION = """\
28
+ The "DeepFruit" dataset is a comprehensive collection designed for the advancement of research in fruit detection, recognition, and classification.
29
+ The type of fruit is determined by various external appearance features. The dataset, from Mendeley, comprises 21,122 images of 20 diverse fruit types across 8 different combinations. This dataset includes separate images and CSV files for training and testing, each containing varying quantities of each fruit. The objective of this study is to convert fruit images into the PIL (Python Imaging Library) format.
30
+ """
31
+ _URLS = {
32
+ "train": 'https://huggingface.co/datasets/sc890/deepfruit_dataset/resolve/main/Fruits_Dataset_Train.zip',
33
+ "test": 'https://huggingface.co/datasets/sc890/deepfruit_dataset/resolve/main/Fruits_Dataset_Test.zip',
34
+ }
35
+ class DeepFruitDataset(datasets.GeneratorBasedBuilder):
36
+ BUILDER_CONFIGS = [
37
+ BuilderConfig(name="deepfruit_dataset", version=Version("1.0.0"))
38
+ ]
39
+ _URLS = _URLS
40
+ def _info(self):
41
+ return datasets.DatasetInfo(
42
+ description=_DESCRIPTION,
43
+ features= datasets.Features({
44
+ "image_id": datasets.Value("string"),
45
+ "number":datasets.Value("int32"),
46
+ "image": datasets.Image(),
47
+ "image_path": datasets.Value("string"),
48
+ "label": datasets.Value("string"),
49
+ }),
50
+ homepage="https://data.mendeley.com/datasets/5prc54r4rt/1",
51
+ license="Mendeley License: CC BY 4.0",
52
+ )
53
+
54
+ def _split_generators(self, dl_manager):
55
+ urls_to_download = self._URLS
56
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
57
+ print(downloaded_files)
58
+ return [
59
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"], "folder": "Fruits_Dataset_Train", "csv_name": "Labels_Train.csv"}),
60
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"], "folder": "Fruits_Dataset_Test","csv_name": "Labels_Test.csv"}),
61
+ ]
62
+
63
+ def _generate_examples(self, filepath, folder, csv_name=None):
64
+ path = os.path.join(filepath, folder, csv_name)
65
+ label_dict = {}
66
+ count = 0
67
+ with open(path, 'r') as file:
68
+ for line in file:
69
+ if count == 0:
70
+ count += 1
71
+ continue
72
+ image_name = line.split(",")[0]
73
+ label = line.replace(image_name, "")
74
+ label = label.replace(",", "")
75
+ label = label.replace("\n", "")
76
+ label_dict[image_name] = label
77
+
78
+ for number_dir in range(1, 9):
79
+ image_dir = os.path.join(filepath,folder, str(number_dir))
80
+ for image_file in os.listdir(image_dir):
81
+ if not image_file.endswith('.jpg'):
82
+ continue
83
+ last_dot_index = image_file.rfind('.')
84
+ if last_dot_index != -1:
85
+ image_id = image_file[:last_dot_index]
86
+ else:
87
+ image_id = image_file
88
+ image_id = str(number_dir) + image_id
89
+ image_path = os.path.join(image_dir, image_file)
90
+ relative_image_path = os.path.relpath(image_path, start=filepath)
91
+ img = IMG.open(image_path)
92
+ yield image_id, {
93
+ "image_id": image_id,
94
+ "number": number_dir,
95
+ "image": img,
96
+ "image_path": relative_image_path,
97
+ "label": label_dict[image_file]
98
+ }