Icon

Building CNN Predictor for cats and dogs images - Deep Learning

There has been no title set for this workflow's metadata.

Classifying Images of Cats and Dogs - Training

This workflow reads images of cats and dogs, performs some simple preprocessing, and trains and evaluates a Convolutional Neural Network (CNN) that is able to distinguish cat images from dog images.

Reference:
F. Villaroel Ordenes & R. Silipo, “Machine learning for marketing on the KNIME Hub: The development of a live repository for marketing applications”, Journal of Business Research 137(1):393-410, DOI: 10.1016/j.jbusres.2021.08.036.

URL: Dataset on Kaggle https://www.kaggle.com/c/dogs-vs-cats/data

Annotations and comments
  • Classifying Images of Cats and Dogs - Training This workflow reads images of cats and dogs, performs some image preprocessing, and trains and evaluates a Convolutional Neural Network (CNN) for image classification.
  • 1. Define network architecture: The Keras Layer nodes define a CNN for a binary image classification task. You can add more convolutional layers to improve the performance.
  • 3. Train, execute, and evalutate network: The Keras Network Learner nodes train the Keras network. In the configuration window you can define the loss functions and the training parameters. The Learning Monitor view of the node shows the performance improvement during training. The Conda Environment Propagation node ensures the existence of a Conda environment with all packages. Another option is to setup your Python integration to use a Conda environment with all packages as described here: https://docs.knime.com/2021-12/deep_learning_installation_guide/index.html#dl_python_setup
  • 2. Read and preprocess images: This workflow part reads the images of cats and dogs, encodes the two classes (cats = 1 and dogs = 0), and performs some image preprocessing -- e.g., normalization of the images to be represented with values between 0 and 1 (Image Calculator), resizing the images to a fixed size (Image Resizer node).
  • IMPORTANT! To execute the workflow you need to download the training dataset from Kaggle and update the path in the List Files / Folders Node inside this metanode. The path should point to the unzipped folder including the images. https://www.kaggle.com/c/dogs-vs-cats/data
  • Remove superfluous columns
  • Set up conda environment
  • Normalize between 0..1
  • Read images
  • Resize to 150x150
  • filters: 32 kernel size: 3x3 activation: ReLU
  • units: 64 kernel size: 3x3 activation: ReLU
  • units: 64 activation: ReLU
  • units: 1 activation: sigmoid
  • dropout: 0.5
  • shape: 150, 150, 3
  • pool size: 2x2
  • Apply the model on new data
  • Train the model for 10 epochs (Adam) with loss function binary cross entropy
  • Save model
  • Select folder with with images
  • We only work with 4000 randomly selected images. You can adjust the number as desired.
  • First 12500 rows are cats, remaining rows are dogs
  • Sort by path name.
  • output >= 0.5 Cat output < 0.5 Dog
  • Encode classes with 0 and 1
  • Evaluate the model Accuracy (74%)

Nodes

Extensions

Links