# Tuning Image Classifier

**URL:** <https://community.konduit.ai/t/tuning-image-classifier/463>\
**Category:** Tuning Help\
**Created:** [April 27, 2020, 7:58pm UTC](https://community.konduit.ai/t/tuning-image-classifier/463 "2020-04-27T19:58:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![camhammel](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@camhammel](https://community.konduit.ai/u/camhammel)\
**Post date:** [April 27, 2020, 7:58pm UTC](https://community.konduit.ai/t/tuning-image-classifier/463/1 "2020-04-27T19:58:59Z")

</div>

Hi everyone,

From the help of @treo and various others in this community, I’ve been able to get my CNN up and running very quickly! I was just wondering if there’s anything I can change to increase the accuracy of the model. I’m currently running a setup on the following data:

- 180 classes/labels/birds
- ~25,000 training images (224x224, 3 channels)
- 900 testing images
- 900 validation images

I’m using a CNN with the following characteristics:

7 layers (incl. output layer):

- Convulutional (1,1 strides, weightInit Xavier, activation Relu)
- Subsampling layer (2,2 strides, pooling type MAX)
- Convulutional (1,1 strides, weightInit Xavier, activation Relu)
- Subsampling layer (2,2 strides, pooling type MAX)
- Convulutional (1,1 strides, weightInit Xavier, activation Relu)
- Subsampling layer (2,2 strides, pooling type MAX)
- Output layer (LossFN negative-log-likelihood, activation softmax, weightinit xavier)

Misc parameters:

- Optimization using stochastic gradient descent
- l2 of 0.004
- Learning rate of 0.001
- Momentum of 0.9
- Early Stopping Trainer terminating after 50 epochs or 60 mins, evaluating on validation set every 2 epochs

With this setup, I’m currently getting an average of approximately 45-55% accuracy across the testing set after producing the model from the earlyStoppingTrainer. It might also be important to note that I’m running this network using CUDA 10.2 with a GTX 1080.

The full source code is uploaded to Github [here.](https://github.com/camhammel/CNN/blob/master/src/main/java/org/example/App.java)

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![treo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/treo/32/47_2.png) [@treo](https://community.konduit.ai/u/treo)\
**Post date:** [April 28, 2020, 6:45am UTC](https://community.konduit.ai/t/tuning-image-classifier/463/2 "2020-04-28T06:45:54Z")

</div>

The dataset you are working with is significantly more complex than MNIST, so I’d start with an architecture that is more suited for the task.

Take a look at the LeNet based model in the Animal Classification example, or the architecture from the Cifar Example.

---

<div class="post-metadata">

**Author:** ![camhammel](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@camhammel](https://community.konduit.ai/u/camhammel)\
**Post date:** [April 28, 2020, 7:38pm UTC](https://community.konduit.ai/t/tuning-image-classifier/463/3 "2020-04-28T19:38:45Z")

</div>

I’ve implemented an architecture similar to the one from the CIFAR animal classification example with much better results now, thank you for your help!

---

<div class="post-metadata">

**Author:** ![phong-phuong](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/phong-phuong/32/229_2.png) [@phong-phuong](https://community.konduit.ai/u/phong-phuong)\
**Post date:** [June 12, 2020, 4:03pm UTC](https://community.konduit.ai/t/tuning-image-classifier/463/4 "2020-06-12T16:03:27Z")

</div>

There’s a resnet model in the model zoo. Am I right to say we can use that pretrained model and use transfer learning to get better scores? Unfortunately there isn’t an example that I know of.

---

<div class="post-metadata">

**Author:** ![treo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/treo/32/47_2.png) [@treo](https://community.konduit.ai/u/treo)\
**Post date:** [June 13, 2020, 7:03pm UTC](https://community.konduit.ai/t/tuning-image-classifier/463/5 "2020-06-13T19:03:33Z")

</div>

@phong-phuong  
[https://deeplearning4j.konduit.ai/tuning-and-training/transfer-learning](https://deeplearning4j.konduit.ai/tuning-and-training/transfer-learning)

This shows how to use transfer learning.

So yes, you can use a model from the model zoo and apply transfer learning to it to make it fit your actual task better.

---

<div class="post-metadata">

**Author:** ![lavajaw](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/lavajaw/32/118_2.png) [@lavajaw](https://community.konduit.ai/u/lavajaw)\
**Post date:** [October 13, 2020, 1:08pm UTC](https://community.konduit.ai/t/tuning-image-classifier/463/6 "2020-10-13T13:08:36Z")

</div>

Hi @camhammel,

I recommend using DenseNet example for image classification :

> **[deeplearning4j-examples/dl4j-examples/src/main/java/org/deeplearning4j/examples/...](https://github.com/eclipse/deeplearning4j-examples/tree/master/dl4j-examples/src/main/java/org/deeplearning4j/examples/advanced/modelling/densenet)**
>
> master/dl4j-examples/src/main/java/org/deeplearning4j/examples/advanced/modelling/densenet

I had very good results with that arhitecture. Also please check my latest PR on that example:

> <https://github.com/eclipse/deeplearning4j-examples/pull/1006>
>
> \## What changes were proposed in this pull request?
> 
> This example was contribu…ted by me, but I noticed few problems in architecture. Now I fixed connection between some layers.
> 
> \## How was this patch tested?
> 
> (Please explain how this patch was tested. E.g. unit tests, integration tests, manual tests)
> 
> Please review
> https://github.com/eclipse/deeplearning4j/blob/master/CONTRIBUTING.md before opening a pull request.

In fixed some mistakes that I made initially when created that example.

Also i think that for your dataset this model might be overwhelming, so I recommend to start with only 2 or 3 dense blocks (In example it has 4 dense bloks), and with growRate like 16…

If you want to read more about DenseNet please check this:

> **[Understanding and visualizing DenseNets](https://towardsdatascience.com/understanding-and-visualizing-densenets-7f688092391a)**
>
> This post be found in PDF here.

Have a nice day
