Icon

01_​Classifiying_​Cats_​and_​Dogs_​Training

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.

If you use this workflow, please cite:
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

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).
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/2019-06/deep_learning_installation_guide/index.html#dl_python_setup
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
Classifying Images of Cats and Dogs - TrainingThis workflow reads images of cats and dogs, performs some image preprocessing, and trains and evaluates a Convolutional Neural Network (CNN) for image classification.
pool size: 2x2
Keras Max Pooling 2D Layer
Table Partitioner
units: 64kernel size: 3x3activation: ReLU
Keras Convolution 2D Layer
Remove superfluous columns
Column Filter
Set up condaenvironment
Conda Environment Propagation
Save model
Keras Network Writer
Train the model for 10 epochs (Adam) withloss function binary crossentropy
Keras Network Learner
Keras Flatten Layer
Apply the modelon new data
Keras Network Executor
dropout: 0.5
Keras Dropout Layer
Encode classeswith 0 and 1
Rule Engine
units: 64activation: ReLU
Keras Dense Layer
Evaluate the modelAccuracy (73%)
Scorer
units: 1activation: sigmoid
Keras Dense Layer
output >= 0.5 Catoutput < 0.5 Dog
Rule Engine
shape: 150, 150, 3
Keras Input Layer
Path to training images
Paths to images
Resize to 150x150
Image Resizer
pool size: 2x2
Keras Max Pooling 2D Layer
Read images
Image Reader (Table)
filters: 32kernel size: 3x3activation: ReLU
Keras Convolution 2D Layer
Normalize between 0..1
Image Calculator

Nodes

Extensions

Links