Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
lcskrishna authored Mar 28, 2019
1 parent a5ffbb7 commit bb48a74
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
# fruit-classification-pytorch
Fruit classification using Kaggle Dataset [Fruit-360](https://www.kaggle.com/moltean/fruits) in pytorch
# Fruit Classifier using Pytorch
Fruit classification using Kaggle Dataset [Fruit-360](https://www.kaggle.com/moltean/fruits) in pytorch.
This repository contains some code on :
a) Creation of custom dataset using pytorch. Look at fruit.py to understand how the custom dataset can be prepared from a set of training and test images.
b) Creation of a Network in pytorch which is simplier to create and try out any changes to it.
c) Easy to train and test.

## How to run the test
Make sure to download the directory in a folder.
# Training and Validation of Fruit-360 dataset.

First load the datasets into npy files.
## Step 1
The same concept applies to all different kinds of datasets.
Firstly, load all the images that are downloaded from the above link and convert them into npy files.
Advantage of using npy files is to use only 4 files named train_data.npy, train_labels.npy and validation_data.npy , validation_labels.npy
rather than using thousands of files for pre-processing.

To convert your training and validation dataset into npy files use the below script.

```
python load_dataset.py --dataset-dir <Dataset Path>
```

This creates train_data.npy, train_labels.npy, validation_data.npy, validation_labels.npy

Using this, train and test the fruit dataset using train.py
## Step 2
Use the dataset files that are created above, train the fruit classifier and evaluate the model.

```
python train.py --data-dir <npy files folder>
python train.py --data-dir <npy files folder> [--epochs <default:10>]
```

This generates a log that trains the network for each epoch and finally do inference against the validation dataset spits out the validation accuracy.

This comment has been minimized.

Copy link
@zjgulai

zjgulai Apr 1, 2019

I get this error :RuntimeError: Assertion `cur_target >= 0 && cur_target < n_classes' failed. at /Users/distiller/project/conda/conda-bld/pytorch-nightly_1553836411291/work/aten/src/THNN/generic/ClassNLLCriterion.c:92

This comment has been minimized.

Copy link
@lcskrishna

lcskrishna Apr 1, 2019

Author Owner

Hi @zjgulai Thanks for informing. Can you please raise an issue in this repository and steps to reproduce?

This comment has been minimized.

Copy link
@zjgulai

zjgulai Apr 2, 2019

I download the Fruit-360 from the https://www.kaggle.com/moltean/fruits and have 94 different kinds.When I didin't change your codes,I have meet the error:main()
File "train.py", line 107, in main
losses, net = train_network(dataloader_train)
File "train.py", line 57, in train_network
loss = criterion(y_pred, y)
File "/Users/apple/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/nn/modules/module.py", line 489, in call
result = self.forward(*input, **kwargs)
File "/Users/apple/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/nn/modules/loss.py", line 904, in forward
ignore_index=self.ignore_index, reduction=self.reduction)
File "/Users/apple/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/nn/functional.py", line 1970, in cross_entropy
return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
File "/Users/apple/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/nn/functional.py", line 1790, in nll_loss
ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
RuntimeError: Assertion `cur_target >= 0 && cur_target < n_classes' failed. at /Users/soumith/mc3build/conda-bld/pytorch_1549597882250/work/aten/src/THNN/generic/ClassNLLCriterion.c:93
when I decrease the import fruit numbers <64,it is normal. I don't why, could you help me please?

This comment has been minimized.

Copy link
@lcskrishna

lcskrishna Apr 2, 2019

Author Owner


0 comments on commit bb48a74

Please sign in to comment.