What is CNN?
In simple terms, a convolutional neural network (CNN) is a type of Artificial neural network.
Where to use CNN?
CNN is widely used for image/object recognition and classification.
How to build CNN?
By following the steps it's easy to build the CNN model
- Step 1: Data
- Step 2: Convolution layer & Input size
- Step 3: Pooling layer
- Step 4: Fully connected layer & Flatten layer
- Step 5: Output layer
- All the layers will have the activation function.
- We know that if we want to create a CNN model we need the training data. But if you want to know whether your model is performing well, you need validation data.
- Today in our blog we'll understand the training and validation data split by ImageDataGenerator.
What is ImageDataGenerator?
ImageDataGenerator in Keras takes the input of the original data and transforms it into multiple data based on user-defined parameters.
- Initializing ImageDataGenerator with some parameters including validation_split.
👀train_datagen = ImageDataGenerator(rescale=1./255,shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,validation_split=0.2) # set validation split (20% data will be in validation split)👀
- Passing 80% of data into training and 20% of data into validation with subset parameters.
👀train_generator = train_datagen.flow_from_directory(train_data_dir,target_size=(img_height, img_width),batch_size=batch_size,class_mode='binary' or 'categorical',subset='training') # set as training data👀
👀validation_generator = train_datagen.flow_from_directory(train_data_dir, # same directory as training datatarget_size=(img_height, img_width),batch_size=batch_size,class_mode='binary' or 'categorical',subset='validation') # set as validation data👀
- For building/training the CNN model, either fit or fit_generator functions can be used. If you have done data augmentation, go with the fit_generator function as shown below.
👀model.fit_generator(
train_generator,
steps_per_epoch = train_generator.samples // batch_size,
validation_data = validation_generator,
validation_steps = validation_generator.samples // batch_size,
epochs = nb_epochs)👀
Hopefully, this article helps you to understand CNN & Keras ImageDataGenerator. Thanks.
The media shown in this article is not owned by SPHVIBE and is used at the Author’s discretion.
No comments:
Post a Comment