This project will use deep learning method to build a training and testing system for fruit classification recognition, and implement a simple fruit image classification recognition system. At present, the fruit classification recognition based on ResNet18 supports 262 fruit classification recognition. On the fruit data set Fruit-Dataset, the Accuracy of the train set is about 95%, the Accuracy of the test set is about 83%, and the backbone network can support googlenet, resnet [18,34,50], inception_v3, mobilenet_v2 and other common models.

Share a fruit dataset Fruit-Dataset, which contains 262 different types of fruits, including common apple, banana, etc., with a total of 225,640 fruit images, which can meet the needs of deep learning fruit classification and recognition.
If you have any questions or need the full code or data or need customized development requirements, you can contact me Email Mail me : slowlon@foxmail.com
Fruit-Dataset contains 262 fruits, including:
A directory name represents a label, and all image data under that label in each directory (images are numbered, but numbers may be missing).
Varieties of the same fruit are typically stored in the same catalog (e.g. green apples, yellow apples, and red apples).
The fruit images present in the dataset can contain fruit at all stages of its life, as well as fruit slices.
The image contains at least 50% fruit information.
The background of an image can be anything: a monochromatic background, human hands, the natural habitat of a fruit, leaves, etc.
There are no duplicate images, but there are some images (with the same label) that are highly similar.
The image may contain a small watermark.
For some uncommon fruits, data is difficult to collect, with only 50 to 100 images. In practical projects, it can be discarded to achieve better balance and fewer varieties.
Tips:
After the training is completed, on the fruit dataset Fruit-Dataset, the Accuracy of the training dataset is about 95%, the Accuracy of the test set is about 83%, and the backbone network can support common models such as googlenet, resnet [18, 34, 50], inception_v3, mobilenet_v2. If you want to further improve the accuracy, you can try:
The most important thing is to clean the dataset, the fruit dataset Fruit-Dataset, some of the data is crawled online, and there are some wrong pictures. Although I have cleaned some of them, I still recommend that you clean the dataset again before training, otherwise it will affect the recognition accuracy of the model.
Use different backbone models such as resnet50 or deeper
Added data enhancement: Already supported: random cropping, random flipping, random rotation, color transformation and other data enhancement methods, you can try more complex data enhancement methods such as mixup, CutMix, etc
Sample Balancing: Sample Balancing is recommended
Overparameter tuning: such as learning rate tuning strategies, optimizers (SGD, Adam, etc.)Loss function: At present, the training code has supported: cross entropy,
LabelSmoothing, you can try FocalLoss and other loss functions
How to use?
demo.py file is used to reason and test the effect of the model, fill in the configuration file, model file and test picture to run the test
1 | <span id="faab" data-selectable-paragraph=""><span>def</span> <span>get_parser</span>():<br> <br> config_file = <span>"data/pretrained/resnet18_1.0_CrossEntropyLoss_20220826100725/config.yaml"</span><br> <br> model_file = <span>"data/pretrained/resnet18_1.0_CrossEntropyLoss_20220826100725/model/best_model_098_83.5305.pth"</span><br> <br> image_dir = <span>"data/test_images/fruit"</span><br> parser = argparse.ArgumentParser(description=<span>"Inference Argument"</span>)<br> parser.add_argument(<span>"-c"</span>, <span>"--config_file"</span>, <span>help</span>=<span>"configs file"</span>, default=config_file, <span>type</span>=<span>str</span>)<br> parser.add_argument(<span>"-m"</span>, <span>"--model_file"</span>, <span>help</span>=<span>"model_file"</span>, default=model_file, <span>type</span>=<span>str</span>)<br> parser.add_argument(<span>"--device"</span>, <span>help</span>=<span>"cuda device id"</span>, default=<span>"cuda:0"</span>, <span>type</span>=<span>str</span>)<br> parser.add_argument(<span>"--image_dir"</span>, <span>help</span>=<span>"image file or directory"</span>, default=image_dir, <span>type</span>=<span>str</span>)<br> <span>return</span> parser</span> |
Run the test results:

If you have any questions or need the full code or data or need customized development requirements, you can contact me Email Mail me : slowlon@foxmail.com