<jupyter_start><jupyter_text>//CNN model architecture , basic customised Convolutional Neural Network<jupyter_code>model= tf.keras.models.Sequential([
       tf.keras.layers.Conv2D(32,(3,3),activation='relu',input_shape=(150,150,3)),
       tf.keras.layers.MaxPooling2D(2,2),
       tf.keras.layers.Conv2D(64,(3,3),activation='relu'),
       tf.keras.layers.MaxPooling2D(2,2),
       tf.keras.layers.Conv2D(128,(3,3),activation='relu'),
       tf.keras.layers.MaxPooling2D(2,2),
       tf.keras.layers.Conv2D(128,(3,3),activation='relu'),
       tf.keras.layers.MaxPooling2D(2,2),
       tf.keras.layers.Dropout(0.5),
       tf.keras.layers.Flatten(),
       tf.keras.layers.Dense(512, activation='relu'),
       tf.keras.layers.Dense(1,activation ='sigmoid')

])
model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])
history=model.fit(train_generator,steps_per_epoch=50, epochs=50, validation_data=validation_generator,validation_steps=50,verbose=2)<jupyter_output>Epoch 1/50
50/50 - 6s - loss: 0.5003 - accuracy: 0.7360 - val_loss: 0.8442 - val_accuracy: 0.5530
Epoch 2/50
50/50 - 6s - loss: 0.5595 - accuracy: 0.6880 - val_loss: 0.7637 - val_accuracy: 0.4820
Epoch 3/50
50/50 - 6s - loss: 0.5598 - accuracy: 0.6960 - val_loss: 0.8005 - val_accuracy: 0.5110
Epoch 4/50
50/50 - 6s - loss: 0.5096 - accuracy: 0.7180 - val_loss: 0.8040 - val_accuracy: 0.5260
Epoch 5/50
50/50 - 6s - loss: 0.4718 - accuracy: 0.7550 - val_loss: 0.9851 - val_accuracy: 0.5740
Epoch 6/50
50/50 - 6s - loss: 0.5026 - accuracy: 0.7260 - val_loss: 0.7871 - val_accuracy: 0.5510
Epoch 7/50
50/50 - 6s - loss: 0.4895 - accuracy: 0.7480 - val_loss: 0.6808 - val_accuracy: 0.5740
Epoch 8/50
50/50 - 6s - loss: 0.5308 - accuracy: 0.7150 - val_loss: 0.8362 - val_accuracy: 0.5360
Epoch 9/50
50/50 - 6s - loss: 0.4681 - accuracy: 0.7580 - val_loss: 0.8003 - val_accuracy: 0.5850
Epoch 10/50
50/50 - 6s - loss: 0.4793 - accuracy: 0.7680 - val_loss: 1.0267 - val_accuracy: 0.5730
Epoch 11/50
50/50 -[...]<jupyter_text>VGG Net with Keras<jupyter_code>from keras.models import Sequential 
from keras.layers import Dense, Conv2D, MaxPooling2D, Dropout
from keras.layers import Flatten, Activation
custom_vgg = Sequential()
custom_vgg.add(Conv2D(32, (3, 3), strides = 1, padding = "same", activation = "relu", input_shape = (150, 150, 3)))
custom_vgg.add(Dropout(0.4))
custom_vgg.add(Conv2D(32, (3, 3), strides = 1, padding = "same", activation = "relu"))
custom_vgg.add(Dropout(0.4))
custom_vgg.add(MaxPooling2D((2, 2)))

custom_vgg.add(Conv2D(64, (3, 3), strides = 1, padding = "same", activation = "relu"))
custom_vgg.add(Dropout(0.4))
custom_vgg.add(Conv2D(64, (3, 3), strides = 1, padding = "same", activation = "relu"))
custom_vgg.add(Dropout(0.4))
custom_vgg.add(MaxPooling2D((2, 2)))

custom_vgg.add(Conv2D(128, (3, 3), strides = 1, padding = "same", activation = "relu"))
custom_vgg.add(Dropout(0.4))
custom_vgg.add(Conv2D(128, (3, 3), strides = 1, padding = "same", activation = "relu"))
custom_vgg.add(Dropout(0.4))
custom_vgg.add(MaxPooling2D((2, 2)))

custom_vgg.add(Flatten())
custom_vgg.add(Dense(1, activation = "softmax"))

custom_vgg.compile(optimizer = "adam", loss = "categorical_crossentropy", metrics = ["accuracy"])

custom_vgg.summary()
history=custom_vgg.fit(train_generator, steps_per_epoch= 30, epochs=50, validation_data=validation_generator,validation_steps=50,verbose=2)

import matplotlib.pyplot as plt
acc = history.history['accuracy']
val_acc = history.history['val_accuracy']
loss = history.history['loss']
val_loss = history.history['val_loss']

epochs = range(len(acc))

plt.plot(epochs, acc, 'bo', label='Training accuracy')
plt.plot(epochs, val_acc, 'r', label='Validation accuracy')
plt.title('Training and validation accuracy')

plt.figure()

plt.plot(epochs, loss, 'bo', label='Training Loss')
plt.plot(epochs, val_loss, 'r', label='Validation Loss')
plt.title('Training and validation loss')
plt.legend()

plt.show()<jupyter_output><empty_output><jupyter_text>ResNet (Residual Network) //connecting a layer to the previous as well as previous of previous for better incorporation.<jupyter_code>model_AlexNet=keras.models.Sequential([
    keras.layers.Conv2D(filters=96, kernel_size=(11,11), strides=(4,4), activation='relu', input_shape=(150,150,3)),
    keras.layers.BatchNormalization(),
    keras.layers.MaxPool2D(pool_size=(3,3), strides=(2,2)),
    keras.layers.Conv2D(filters=256, kernel_size=(5,5), strides=(1,1), activation='relu', padding="same"),
    keras.layers.BatchNormalization(),
    keras.layers.MaxPool2D(pool_size=(3,3), strides=(2,2)),
    keras.layers.Conv2D(filters=384, kernel_size=(3,3), strides=(1,1), activation='relu', padding="same"),
    keras.layers.BatchNormalization(),
    keras.layers.Conv2D(filters=384, kernel_size=(1,1), strides=(1,1), activation='relu', padding="same"),
    keras.layers.BatchNormalization(),
    keras.layers.Conv2D(filters=256, kernel_size=(1,1), strides=(1,1), activation='relu', padding="same"),
    keras.layers.BatchNormalization(),
    keras.layers.MaxPool2D(pool_size=(3,3), strides=(2,2)),
    keras.layers.Flatten(),
    keras.layers.Dense(4096, activation='relu'),
    keras.layers.Dropout(0.3),
    keras.layers.Dense(4096, activation='relu'),
    keras.layers.Dropout(0.3),
    keras.layers.Dense(1024, activation='relu'),

    keras.layers.Dense(1, activation='softmax')])


model_AlexNet.compile(loss='binary_crossentropy',optimizer=tf.optimizers.SGD(lr=0.001),metrics=['accuracy'])
model_AlexNet.summary()
history=model_AlexNet.fit(train_generator,epochs=50, steps_per_epoch=50,validation_data=validation_generator,validation_steps=20,verbose=2)

import matplotlib.pyplot as plt
acc = history.history['accuracy']
val_acc = history.history['val_accuracy']
loss = history.history['loss']
val_loss = history.history['val_loss']

epochs = range(len(acc))

plt.plot(epochs, acc, 'bo', label='Training accuracy')
plt.plot(epochs, val_acc, 'r', label='Validation accuracy')
plt.title('Training and validation accuracy')

plt.figure()

plt.plot(epochs, loss, 'bo', label='Training Loss')
plt.plot(epochs, val_loss, 'r', label='Validation Loss')
plt.title('Training and validation loss')
plt.legend()

plt.show()
import time
t = time.time()
export_path_keras = "./{}.h5".format(int(t))
print(export_path_keras)
model_AlexNet.save(export_path_keras)<jupyter_output>./1611941883.h5<jupyter_text>Inception<jupyter_code>from keras.models import Model
from keras.layers import Input
from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras.layers.merge import concatenate
from keras.utils import plot_model
 
# function for creating a projected inception module
def inception_module(layer_in, f1, f2_in, f2_out, f3_in, f3_out, f4_out):
	# 1x1 conv
	conv1 = Conv2D(f1, (1,1), padding='same', activation='relu')(layer_in)
	# 3x3 conv
	conv3 = Conv2D(f2_in, (1,1), padding='same', activation='relu')(layer_in)
	conv3 = Conv2D(f2_out, (3,3), padding='same', activation='relu')(conv3)
	# 5x5 conv
	conv5 = Conv2D(f3_in, (1,1), padding='same', activation='relu')(layer_in)
	conv5 = Conv2D(f3_out, (5,5), padding='same', activation='relu')(conv5)
	# 3x3 max pooling
	pool = MaxPooling2D((3,3), strides=(1,1), padding='same')(layer_in)
	pool = Conv2D(f4_out, (1,1), padding='same', activation='relu')(pool)
	# concatenate filters, assumes filters/channels last
	layer_out = concatenate([conv1, conv3, conv5, pool], axis=-1)
	return layer_out
 
# define model input
visible = Input(shape=(150, 150, 3))
# add inception block 1
layer = inception_module(visible, 64, 96, 128, 16, 32, 32)
# add inception block 1
layer = inception_module(layer, 128, 128, 192, 32, 96, 64)
# create model




# summarize model




from tensorflow.keras.optimizers import RMSprop 
from tensorflow.keras.preprocessing.image import ImageDataGenerator 
from tensorflow.keras import layers 
from tensorflow.keras import Model 
from tensorflow.keras.applications.inception_v3 import InceptionV3 
from tensorflow.keras.optimizers import RMSprop 

base_model = InceptionV3(input_shape = (150, 150, 3),  
                                include_top = False,  
                                weights = 'imagenet') 
for layer in base_model.layers: 
  layer.trainable = False
  
#stop training is model accuracy reached 99% 
class myCallback(tf.keras.callbacks.Callback): 
  def on_epoch_end(self, epoch, logs={}): 
    if(logs.get('acc')>0.99): 
      self.model.stop_training = True


x = layers.Flatten()(base_model.output) 
x = layers.Dense(1024, activation='relu')(x) 
x = layers.Dropout(0.2)(x)                   
x = layers.Dense  (1, activation='sigmoid')(x)            
  
model5 = Model( base_model.input, x)  
  
model5.compile(optimizer = RMSprop(lr=0.0001),loss = 'binary_crossentropy',metrics = ['acc']) 
callbacks = myCallback() 
  
history = model5.fit( 
            train_generator, 
            validation_data = validation_generator, 
            steps_per_epoch = 100, 
            epochs = 30, 
            validation_steps = 50, 
            verbose = 2, 
            callbacks=[callbacks]) 

import matplotlib.pyplot as plt
acc = history.history['acc']
val_acc = history.history['val_acc']
loss = history.history['loss']
val_loss = history.history['val_loss']

epochs = range(len(acc))

plt.plot(epochs, acc, 'bo', label='Training accuracy')
plt.plot(epochs, val_acc, 'r', label='Validation accuracy')
plt.title('Training and validation accuracy')

plt.figure()

plt.plot(epochs, loss, 'bo', label='Training Loss')
plt.plot(epochs, val_loss, 'r', label='Validation Loss')
plt.title('Training and validation loss')
plt.legend()

plt.show()

import time
t = time.time()
export_path_keras = "./{}.h5".format(int(t))
print(export_path_keras)
model5.save(export_path_keras)
import time
t = time.time()
export_path_keras = "./{}.h5".format(int(t))
print(export_path_keras)
.save(export_path_keras)
model= tf.keras.models.Sequential([
       tf.keras.layers.Conv2D(32,(3,3),activation='relu',input_shape=(150,150,3)),
       tf.keras.layers.MaxPooling2D(2,2),
       tf.keras.layers.Conv2D(64,(3,3),activation='relu'),
       tf.keras.layers.MaxPooling2D(2,2),
       tf.keras.layers.Conv2D(128,(3,3),activation='relu'),
       tf.keras.layers.MaxPooling2D(2,2),
       tf.keras.layers.Conv2D(128,(3,3),activation='relu'),
       tf.keras.layers.MaxPooling2D(2,2),
       tf.keras.layers.Dropout(0.5),
       tf.keras.layers.Flatten(),
       tf.keras.layers.Dense(512, activation='relu'),
       tf.keras.layers.Dense(1,activation ='sigmoid')

])
model4.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])
history=model.fit(train_generator, steps_per_epoch=100,epochs=100,validation_data=validation_generator,validation_steps=50,verbose=2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15602448159313054, 'fraction_numerical': 0.06513199963460309, 'mean_word_length': 4.585714285714285, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '296575', 'license': 'MIT', 'n_tokens_mistral': 4539, 'n_tokens_neox': 4060, 'n_words': 721, 'path': 'Model Architecture.ipynb', 'repo_name': 'kakamband/Espial', 'size': '10947'}