from tensorflow import python as tf
from keras.preprocessing.image import ImageDataGenerator
import pandas as pd


train_datagen = ImageDataGenerator(rescale=1./255,
                                   shear_range=0.2,
                                   zoom_range=0.2,
                                   horizontal_flip=False)

test_datagen = ImageDataGenerator(rescale=1./255)



training_set = train_datagen.flow_from_directory('data2/masked_rotated_h_train/small vehicle/',
                                                 target_size=(30, 75),
                                                 batch_size=32,
                                                 class_mode='categorical')

test_set = test_datagen.flow_from_directory('data2/masked_rotated_h_test/small vehicle/',
                                            target_size=(30, 75),
                                            batch_size=32,
                                            class_mode='categorical')

# Initialising
cnn_classifier = tf.keras.models.Sequential()

# 1st conv. layer
cnn_classifier.add(tf.keras.layers.Conv2D(64, (3, 3), input_shape=(30, 75, 3), activation='relu'))
cnn_classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))

# 2nd conv. layer
cnn_classifier.add(tf.keras.layers.Conv2D(128, (3, 3), activation='relu'))
cnn_classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))

# 3nd conv. layer
cnn_classifier.add(tf.keras.layers.Conv2D(256, (3, 3), activation='relu'))
cnn_classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))

# Flattening
cnn_classifier.add(tf.keras.layers.Flatten())


# Full connection
cnn_classifier.add(tf.keras.layers.Dense(units=256, activation='relu'))
cnn_classifier.add(tf.keras.layers.Dropout(0.5))
cnn_classifier.add(tf.keras.layers.Dense(units=6, activation='sigmoid'))

cnn_classifier.summary()
# Compiling the CNN
cnn_classifier.compile(optimizer='adam',
                       loss='categorical_crossentropy',
                       metrics=['accuracy'])

cnn_classifier.fit_generator(training_set,
                             steps_per_epoch=6406,
                             epochs=10,
                             validation_data=test_set,
                             validation_steps=903)

# saving model and weights
cnn_classifier.save_weights('data2/vehicle_classification_weights_dropout.h5')
cnn_classifier.save('data2/vehicle_classification_model_dropout.h5')

5970493602105c1e176675ec77dd644d4c739a5d
<mask token>

<mask token>
cnn_classifier.add(tf.keras.layers.Conv2D(64, (3, 3), input_shape=(30, 75, 
    3), activation='relu'))
cnn_classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))
cnn_classifier.add(tf.keras.layers.Conv2D(128, (3, 3), activation='relu'))
cnn_classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))
cnn_classifier.add(tf.keras.layers.Conv2D(256, (3, 3), activation='relu'))
cnn_classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))
cnn_classifier.add(tf.keras.layers.Flatten())
cnn_classifier.add(tf.keras.layers.Dense(units=256, activation='relu'))
cnn_classifier.add(tf.keras.layers.Dropout(0.5))
cnn_classifier.add(tf.keras.layers.Dense(units=6, activation='sigmoid'))
cnn_classifier.summary()
cnn_classifier.compile(optimizer='adam', loss='categorical_crossentropy',
    metrics=['accuracy'])
cnn_classifier.fit_generator(training_set, steps_per_epoch=6406, epochs=10,
    validation_data=test_set, validation_steps=903)
cnn_classifier.save_weights('data2/vehicle_classification_weights_dropout.h5')
cnn_classifier.save('data2/vehicle_classification_model_dropout.h5')

<mask token>
train_datagen = ImageDataGenerator(rescale=1.0 / 255, shear_range=0.2,
    zoom_range=0.2, horizontal_flip=False)
test_datagen = ImageDataGenerator(rescale=1.0 / 255)
training_set = train_datagen.flow_from_directory(
    'data2/masked_rotated_h_train/small vehicle/', target_size=(30, 75),
    batch_size=32, class_mode='categorical')
test_set = test_datagen.flow_from_directory(
    'data2/masked_rotated_h_test/small vehicle/', target_size=(30, 75),
    batch_size=32, class_mode='categorical')
cnn_classifier = tf.keras.models.Sequential()
cnn_classifier.add(tf.keras.layers.Conv2D(64, (3, 3), input_shape=(30, 75, 
    3), activation='relu'))
cnn_classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))
cnn_classifier.add(tf.keras.layers.Conv2D(128, (3, 3), activation='relu'))
cnn_classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))
cnn_classifier.add(tf.keras.layers.Conv2D(256, (3, 3), activation='relu'))
cnn_classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))
cnn_classifier.add(tf.keras.layers.Flatten())
cnn_classifier.add(tf.keras.layers.Dense(units=256, activation='relu'))
cnn_classifier.add(tf.keras.layers.Dropout(0.5))
cnn_classifier.add(tf.keras.layers.Dense(units=6, activation='sigmoid'))
cnn_classifier.summary()
cnn_classifier.compile(optimizer='adam', loss='categorical_crossentropy',
    metrics=['accuracy'])
cnn_classifier.fit_generator(training_set, steps_per_epoch=6406, epochs=10,
    validation_data=test_set, validation_steps=903)
cnn_classifier.save_weights('data2/vehicle_classification_weights_dropout.h5')
cnn_classifier.save('data2/vehicle_classification_model_dropout.h5')

from tensorflow import python as tf
from keras.preprocessing.image import ImageDataGenerator
import pandas as pd
train_datagen = ImageDataGenerator(rescale=1.0 / 255, shear_range=0.2,
    zoom_range=0.2, horizontal_flip=False)
test_datagen = ImageDataGenerator(rescale=1.0 / 255)
training_set = train_datagen.flow_from_directory(
    'data2/masked_rotated_h_train/small vehicle/', target_size=(30, 75),
    batch_size=32, class_mode='categorical')
test_set = test_datagen.flow_from_directory(
    'data2/masked_rotated_h_test/small vehicle/', target_size=(30, 75),
    batch_size=32, class_mode='categorical')
cnn_classifier = tf.keras.models.Sequential()
cnn_classifier.add(tf.keras.layers.Conv2D(64, (3, 3), input_shape=(30, 75, 
    3), activation='relu'))
cnn_classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))
cnn_classifier.add(tf.keras.layers.Conv2D(128, (3, 3), activation='relu'))
cnn_classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))
cnn_classifier.add(tf.keras.layers.Conv2D(256, (3, 3), activation='relu'))
cnn_classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))
cnn_classifier.add(tf.keras.layers.Flatten())
cnn_classifier.add(tf.keras.layers.Dense(units=256, activation='relu'))
cnn_classifier.add(tf.keras.layers.Dropout(0.5))
cnn_classifier.add(tf.keras.layers.Dense(units=6, activation='sigmoid'))
cnn_classifier.summary()
cnn_classifier.compile(optimizer='adam', loss='categorical_crossentropy',
    metrics=['accuracy'])
cnn_classifier.fit_generator(training_set, steps_per_epoch=6406, epochs=10,
    validation_data=test_set, validation_steps=903)
cnn_classifier.save_weights('data2/vehicle_classification_weights_dropout.h5')
cnn_classifier.save('data2/vehicle_classification_model_dropout.h5')

from tensorflow import python as tf
from keras.preprocessing.image import ImageDataGenerator
import pandas as pd


train_datagen = ImageDataGenerator(rescale=1./255,
                                   shear_range=0.2,
                                   zoom_range=0.2,
                                   horizontal_flip=False)

test_datagen = ImageDataGenerator(rescale=1./255)



training_set = train_datagen.flow_from_directory('data2/masked_rotated_h_train/small vehicle/',
                                                 target_size=(30, 75),
                                                 batch_size=32,
                                                 class_mode='categorical')

test_set = test_datagen.flow_from_directory('data2/masked_rotated_h_test/small vehicle/',
                                            target_size=(30, 75),
                                            batch_size=32,
                                            class_mode='categorical')

# Initialising
cnn_classifier = tf.keras.models.Sequential()

# 1st conv. layer
cnn_classifier.add(tf.keras.layers.Conv2D(64, (3, 3), input_shape=(30, 75, 3), activation='relu'))
cnn_classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))

# 2nd conv. layer
cnn_classifier.add(tf.keras.layers.Conv2D(128, (3, 3), activation='relu'))
cnn_classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))

# 3nd conv. layer
cnn_classifier.add(tf.keras.layers.Conv2D(256, (3, 3), activation='relu'))
cnn_classifier.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))

# Flattening
cnn_classifier.add(tf.keras.layers.Flatten())


# Full connection
cnn_classifier.add(tf.keras.layers.Dense(units=256, activation='relu'))
cnn_classifier.add(tf.keras.layers.Dropout(0.5))
cnn_classifier.add(tf.keras.layers.Dense(units=6, activation='sigmoid'))

cnn_classifier.summary()
# Compiling the CNN
cnn_classifier.compile(optimizer='adam',
                       loss='categorical_crossentropy',
                       metrics=['accuracy'])

cnn_classifier.fit_generator(training_set,
                             steps_per_epoch=6406,
                             epochs=10,
                             validation_data=test_set,
                             validation_steps=903)

# saving model and weights
cnn_classifier.save_weights('data2/vehicle_classification_weights_dropout.h5')
cnn_classifier.save('data2/vehicle_classification_model_dropout.h5')
