Giter Site home page Giter Site logo

cogsys-tuebingen / deephs_fruit Goto Github PK

View Code? Open in Web Editor NEW
36.0 7.0 8.0 1.4 MB

Measuring the ripeness of fruit with Hyperspectral Imaging and Deep Learning

Python 100.00%
cnn data-set deep-learning hyperspectral-image-classification hyperspectral-imaging pytorch

deephs_fruit's Introduction

Measuring the Ripeness of Fruit with Hyperspectral Imaging and Deep Learning

Version 2:
    - The training is now more stable
    - Added new hyperspectral recordings
    - Added HyveConv++ model

Version 1 is still avaiable on branch 'paper_version' 

Here you can find the dataset and the official implementation of the HS-CNN network with an optimized training pipeline.

Data set (v2)

The dataset is here or as torrent available. It contains recordings of:

  • Avocados
  • Kiwis
  • Persimmons
  • Papayas
  • Mango

Three hyperspectral cameras were use:

  • Specim FX 10
  • INNO-SPEC Redeye 1.7
  • Corning microHSI 410 Vis-NIR Hyperspectral Sensor

The data set covers four measurement series. Labels are provided as destructive measurements (fruit flesh firmness, sugar content and overall ripeness)

Requirements

  • Python 3.10
  • PyTorch 1.11.0 and the packages defined in the requirements file (pip3 install -r requirements.txt)
  • Download the data set to a local folder

How to train

If all packages are installed and the data set was downloaded, the training can start. This will train the HS-CNN model on the ripeness classification of avocados:

PYTHONPATH=$PYTHONPATH:. python3 classification/train.py --data_path /folder/of/downloaded/dataset/ --model deephs_net --fruit avocado --classification_type ripeness --seed 23312323

Loss
Accuracy
Confusion
Figure 1 - Training of HS-CNN:

And this will train HS-CNN + HyveConv++ on the same classification task:

PYTHONPATH=$PYTHONPATH:. python3 classification/train.py --data_path /folder/of/downloaded/dataset/ --model hyve --fruit avocado --classification_type ripeness --seed 23312323

Loss
Accuracy
Confusion
Figure 2 - Training of HS-CNN + HyveConv++:

PYTHONPATH=$PYTHONPATH:. python3 classification/train.py --help provides helpful information regarding the parameters. For more information about the training framework PyTorch-Lightning, we refer to the official documentation (https://pytorch-lightning.readthedocs.io/en/latest/).

Citation

The paper was presented on IJCNN 2021.

@inproceedings{Varga2021,
abstract = {We present a system to measure the ripeness of fruit with a hyperspectral camera and a suitable deep neural network architecture. This architecture did outperform competitive baseline models on the prediction of the ripeness state of fruit. For this, we recorded a data set of ripening avocados and kiwis, which we make public. We also describe the process of data collection in a manner that the adaption for other fruit is easy. The trained network is validated empirically, and we investigate the trained features. Furthermore, a technique is introduced to visualize the ripening process.},
archivePrefix = {arXiv},
arxivId = {2104.09808},
author = {Varga, Leon Amadeus and Makowski, Jan and Zell, Andreas},
booktitle = {2021 International Joint Conference on Neural Networks (IJCNN)},
doi = {10.1109/IJCNN52387.2021.9533728},
eprint = {2104.09808},
isbn = {978-1-6654-3900-8},
keywords = {Index Terms-hyperspectral,convolutional neu-ral network,deep learning,ripening fruit},
month = {jul},
pages = {1--8},
publisher = {IEEE},
title = {{Measuring the Ripeness of Fruit with Hyperspectral Imaging and Deep Learning}},
url = {https://arxiv.org/abs/2104.09808v1 http://arxiv.org/abs/2104.09808 https://ieeexplore.ieee.org/document/9533728/},
year = {2021}
}

For HyveConv++ please check: https://github.com/cogsys-tuebingen/hyve_conv

deephs_fruit's People

Contributors

leonvarga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

deephs_fruit's Issues

Error on installing h5py

When I tried to create a new conda environment and use pip install -r requirements.txt, I got this error.

error: Could not find module 'hdf5.dll' (or one of its dependencies). Try using the full path with constructor syntax.

I resolved it by using
pip install h5py --only-binary h5py
h5py/h5py#2146

I'm using Windows 10 x64.

Hope this is useful for some one.

Regards,
Lam

Data not available for sugar content

Although code is written for estimating sugar content, and in paper it is also mentioned about sugar content. BUt in annotations.zip labels are not there. How can I get labels for sweetness.

getting low accuracy in Avocado

I followed the same steps to train model, didnt made any changes. But I am getting 0.9 to 1 training accuracy but test accuracy is about 0.25 for Avocado. Can you explain why is it so. And how can I solve this problem.

dataset is corrupted?

Hello, I'm just a beginner and I needed this dataset. I tried to download just one dataset HSI(avocado specifically)just to test it out but every time I try to open, it says it's either corrupted or invalid. Is it possible for you to give me advice on what I might did wrong(e.g wrong app). it's quite urgent so I appreciate a quick reply. Thank you.

Unknown version opencv-python/opencv-contrib-python

When creating a new conda environment and using pip install -r requirements.txt, i got the following error.

ERROR: Could not find a version that satisfies the requirement opencv-python==4.2.0.34 (from versions: 3.4.0.14, 3.4.10.37, 3.4.11.39, 3.4.11.41, 3.4.11.43, 3.4.11.45, 3.4.13.47, 3.4.14.51, 3.4.14.53, 3.4.15.55, 3.4.16.57, 3.4.16.59, 3.4.17.61, 4.3.0.38, 4.4.0.40, 4.4.0.42, 4.4.0.44, 4.4.0.46, 4.5.1.48, 4.5.2.52, 4.5.2.54, 4.5.3.56, 4.5.4.58, 4.5.4.60, 4.5.5.62)
ERROR: No matching distribution found for opencv-python==4.2.0.34

I had the same problem for opencv-contrib-python, scikit-image and torch.

I resolved the problem by removing the version requirement, but I stilled wanted to report so you can check. I think it might also be related to the fact I'm using Linux (Ubuntu 20.04).

How can data images be seen

All the images in dataset are in .bin format. In case I want to convert them to RGB images or I want to see them, Then how can I do this. I tried multiple code to convert bin file to image but none of them is working out.
Or you can tell how you encode the images

cannot run training code on Windows

Dear @leonvarga

Thank you for uploading the direct download link for dataset last time.
I'm now trying to run the training code.

Unfortunately, I encountered the following error. I'm not sure what it points to and have no idea since your code used a module core which I think is related to PBS, but I'm running a windows machine with 2 different GPUs.

Do you have any idea how to fix this?

(HSI_deep_fruit) D:\tmp\HSI\deephs_fruit>python classification/train.py --data_path ../dataset --model deephs_net --fruit avocado --classification_type ripeness --seed 23312323 Global seed set to 23312323 Hparams: {'model': 'deephs_net', 'batch_size': 64, 'lr': 0.01, 'fruit': <Fruit.AVOCADO: 'Avocado'>, 'camera_type': <CameraType.VIS: 'VIS'>, 'classification_type': <ClassificationType.RIPENESS: 'ripeness'>, 'num_epochs': 5000, 'data_path': '../dataset', 'seed': 23312323, 'log_path': None, 'online_logging': False, 'debug': False, 'model_checkpoint': None, 'comment': None, 'camera_agnostic_num_gauss': 5, 'hidden_layers': [25, 30, 50], 'type': 'single_camera', 'git_id': '3a4d7075d2823aceb37b8e6b2919e30d302a53cf', 'slurm_job_id': 'WUDL1329:D:\\tmp\\HSI\\deephs_fruit', 'slurm_job_path': '', 'num_workers': 4, 'bands': 224, 'wavelengths': [397.66, 400.28, 402.9, 405.52, 408.13, 410.75, 413.37, 416.0, 418.62, 421.24, 423.86, 426.49, 429.12, 431.74, 434.37, 437.0, 439.63, 442.26, 444.89, 447.52, 450.16, 452.79, 455.43, 458.06, 460.7, 463.34, 465.98, 468.62, 471.26, 473.9, 476.54, 479.18, 481.83, 484.47, 487.12, 489.77, 492.42, 495.07, 497.72, 500.37, 503.02, 505.67, 508.32, 510.98, 513.63, 516.29, 518.95, 521.61, 524.27, 526.93, 529.59, 532.25, 534.91, 537.57, 540.24, 542.91, 545.57, 548.24, 550.91, 553.58, 556.25, 558.92, 561.59, 564.26, 566.94, 569.61, 572.29, 574.96, 577.64, 580.32, 583.0, 585.68, 588.36, 591.04, 593.73, 596.41, 599.1, 601.78, 604.47, 607.16, 609.85, 612.53, 615.23, 617.92, 620.61, 623.3, 626.0, 628.69, 631.39, 634.08, 636.78, 639.48, 642.18, 644.88, 647.58, 650.29, 652.99, 655.69, 658.4, 661.1, 663.81, 666.52, 669.23, 671.94, 674.65, 677.36, 680.07, 682.79, 685.5, 688.22, 690.93, 693.65, 696.37, 699.09, 701.81, 704.53, 707.25, 709.97, 712.7, 715.42, 718.15, 720.87, 723.6, 726.33, 729.06, 731.79, 734.52, 737.25, 739.98, 742.72, 745.45, 748.19, 750.93, 753.66, 756.4, 759.14, 761.88, 764.62, 767.36, 770.11, 772.85, 775.6, 778.34, 781.09, 783.84, 786.58, 789.33, 792.08, 794.84, 797.59, 800.34, 803.1, 805.85, 808.61, 811.36, 814.12, 816.88, 819.64, 822.4, 825.16, 827.92, 830.69, 833.45, 836.22, 838.98, 841.75, 844.52, 847.29, 850.06, 852.83, 855.6, 858.37, 861.14, 863.92, 866.69, 869.47, 872.25, 875.03, 877.8, 880.58, 883.37, 886.15, 888.93, 891.71, 894.5, 897.28, 900.07, 902.86, 905.64, 908.43, 911.22, 914.02, 916.81, 919.6, 922.39, 925.19, 927.98, 930.78, 933.58, 936.38, 939.18, 941.98, 944.78, 947.58, 950.38, 953.19, 955.99, 958.8, 961.6, 964.41, 967.22, 970.03, 972.84, 975.65, 978.46, 981.27, 984.09, 986.9, 989.72, 992.54, 995.35, 998.17, 1000.99, 1003.81], 'augmentation_config': {'random_flip': True, 'random_rotate': True, 'random_noise': False, 'random_cut': True, 'random_crop': True, 'random_intensity_scale': False}, 'test_augmentation': True, 'tta_augmentation_config': {'random_flip': True, 'random_rotate': True, 'random_noise': False, 'random_cut': False, 'random_crop': False, 'random_intensity_scale': False}, 'tta_augmentation_iterations': 5, 'num_classes': 3, 'input_size': (64, 64)} Traceback (most recent call last): File "D:\tmp\HSI\deephs_fruit\classification\train.py", line 422, in <module> main(hparams) File "D:\tmp\HSI\deephs_fruit\classification\train.py", line 366, in main logger = WandbLogger(offline=not hparams['online_logging'], save_dir=hparams['log_path'], File "D:\miniconda3_windows\envs\HSI_deep_fruit\lib\site-packages\pytorch_lightning\loggers\wandb.py", line 303, in __init__ dir=save_dir or kwargs.pop("dir"), KeyError: 'dir'

Thanks a lot.
Lam

overfitting the model

Hi,

Running the code on avocado/mango datasets, and I've gotten the code to run and train. However, I've been running into some issues that I believe are overfitting. I've tried both the deephs_fruit and hyve flags, training a minimum of 50 and 100 epochs with multiple seeds, and while I'm getting a relatively high training/validation accuracy ( ~ 80-90%), the test accuracy is also quite low (~25%).

I believe the only change that I have made is using "gloo" instead of "nccl" as ddps strategy. The line I've inserted is:

`ddps = DDPStrategy(process_group_backend="gloo")

trainer = lightning.Trainer(max_epochs=opt.num_epochs, ...
`

around line 388 or so in train.py

Is there a pretrained model that can be shared?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.