import tensorflow as tf
from tensorflow.keras import datasets, layers, models
(x_train,y_train),(x_test, y_test) = datasets.cifar10.load_data()
import matplotlib.pyplot as plt
plt.imshow(x_train[32000])
import cv2
img = x_train[32000]
def normImage(img):
return cv2.normalize(img, None, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F)
normalizedImg = normImage(img)
plt.imshow(x_train[32000])
plt.show()
plt.imshow(normalizedImg)
plt.show()
from tensorflow.keras.layers import Dense, Conv2D, Flatten
from tensorflow.keras import Sequential
model = Sequential()
model.add(layers.Conv2D(32,(3, 3) ,activation='relu',input_shape=(32,32,3)))
model.add(Flatten())
model.add(Dense(units=300,activation='relu'))
model.add(Dense(units=10,activation='sigmoid'))
model.compile(loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
, optimizer='sgd',metrics=['accuracy'])
x_train_norm = normImage(x_train)
x_test_norm = normImage(x_test)
model.fit(x_train_norm, y_train, epochs=10, validation_data=(x_test_norm, y_test))
model = Sequential()
model.add(layers.Conv2D(32,(3, 3) ,activation='relu',input_shape=(32,32,3)))
model.add(layers.Conv2D(32,(3, 3) ,activation='relu',input_shape=(32,32,3)))
model.add(Flatten())
model.add(Dense(units=300,activation='relu'))
model.add(Dense(units=100,activation='relu'))
model.add(Dense(units=10,activation='sigmoid'))
model.compile(loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
, optimizer='sgd',metrics=['accuracy'])
x_train_norm = normImage(x_train)
x_test_norm = normImage(x_test)
model.fit(x_train_norm, y_train, epochs=10, validation_data=(x_test_norm, y_test))
model.summary()
from tensorflow.keras.layers import Dense, Conv2D, Flatten,MaxPooling2D
model = Sequential()
model.add(layers.Conv2D(32,(3, 3) ,activation='relu',input_shape=(32,32,3)))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(layers.Conv2D(32,(3, 3) ,activation='relu',input_shape=(32,32,3)))
model.add(Flatten())
model.add(Dense(units=300,activation='relu'))
model.add(Dense(units=100,activation='relu'))
model.add(Dense(units=10,activation='sigmoid'))
model.compile(loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
, optimizer='sgd',metrics=['accuracy'])
x_train_norm = normImage(x_train)
x_test_norm = normImage(x_test)
model.fit(x_train_norm, y_train, epochs=10, validation_data=(x_test_norm, y_test))
model.summary()
from tensorflow.keras.layers import Dense, Conv2D, Flatten,MaxPooling2D
model = Sequential()
model.add(layers.Conv2D(32,(3, 3) ,activation='relu',input_shape=(32,32,3)))
model.add(MaxPooling2D(pool_size=(4, 4)))
model.add(layers.Conv2D(32,(3, 3) ,activation='relu',input_shape=(32,32,3)))
model.add(Flatten())
model.add(Dense(units=300,activation='relu'))
model.add(Dense(units=100,activation='relu'))
model.add(Dense(units=10,activation='sigmoid'))
model.compile(loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
, optimizer='sgd',metrics=['accuracy'])
x_train_norm = normImage(x_train)
x_test_norm = normImage(x_test)
model.summary()
model.fit(x_train_norm, y_train, epochs=10, validation_data=(x_test_norm, y_test))