Compiling the CNN
model.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])
```
*Data Processing Using Artificial Neural Networks DOI: http://dx.doi.org/10.5772/intechopen.91935*

**Notes/Thanks/Other declarations**

*Dynamic Data Assimilation - Beating the Uncertainties*

Program code for supervised CNN model is given below:

*Step#2 Installing and Import Necessary Data Sources*

from keras.preprocessing.image import ImageDataGenerator

from keras.layers import Activation, Dropout, Flatten, Dense

model.add(Conv2D(64 (3, 3), input\_shape = (150, 150, 3), activation = 'relu'))

64 and 32 represents the number of neurons in these layers.

model.compile(optimizer = 'adam', loss = 'binary\_crossentropy', metrics = ['accuracy'])

The convolutional network helps to extract features from the image and digit 64

*Step#3 CNN Convolutional Network Model*

model.add(MaxPooling2D(pool\_size = (2, 2)))

model.add(Conv2D(64, (3, 3), activation = 'relu')) model.add(MaxPooling2D(pool\_size = (2, 2)))

model.add(Dense(units = 64, activation = 'relu'))

model.add(Dense(units = 32, activation = 'relu'))

model.add(Dense(units = 1, activation = 'sigmoid'))

Python was opened, and conda environment was selected.

Special thanks to UTP

*Step#1 Opening Python*

from keras.models import Sequential from keras.layers import Conv2D, MaxPooling2D

from keras import backend as K from keras.preprocessing import image

import tensorflow as tf import numpy as np

**# Convolutional Layer 1**

**# Convolutional Layer 2**

means to extract 64 features.

model.add(Flatten())

**# Hidden Layer 1**

**# Hidden Layer 2**

**# Output Layer**

**100**

**# Compiling the CNN**

**#Input Layer** model = Sequential()

**Appendix A**

Sigmoid represents the activation function of this model.

*Step#4 Fitting CNN to the Images (Training and Validation)*

```
train_datagen = ImageDataGenerator(rescale = 1./255,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True)
test_datagen = ImageDataGenerator(rescale = 1./255)
training_set = train_datagen.flow_from_directory('Data/Train',
target_size = (150, 150),
batch_size = 12,
class_mode = 'binary')
test_set = test_datagen.flow_from_directory('Data/Validation',
target_size = (150, 150),
batch_size = 8,
class_mode = 'binary')
model.fit_generator(training_set,
steps_per_epoch = 10,
epochs = 4,
validation_data = test_set,
validation_steps = 10)
```
directories are for the path to the training folder and validation folder

*Step#5 Running the ANN Model*

```
test_image = image.load_img('Data/Apple.JPG', target_size = (150, 150))
test_image = image.img_to_array(test_image)
test_image = np.expand_dims(test_image, axis = 0)
result = model.predict(test_image)
training_set.class_indices
if result[0][0] == 1:
 prediction = 'Orange'
else:
 prediction = 'Apple'
print (prediction)
```