Imagenet Dataset and Image Recognition
import tensorflow as tf
from tensorflow import keras
from keras.models import Sequential
from keras.layers import Dense, Flatten, Conv2D, MaxPooling2D, Dropout
from tensorflow.keras import layers
from keras.utils import to_categorical
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
from keras.datasets import cifar10
(x_train, y_train),(x_test, y_test) = cifar10.load_data()
plt.imshow(x_train[0])
y_train_one_hot = to_categorical(y_train)
y_test_one_hot = to_categorical(y_test)
x_train = x_train/255
x_test = x_test/255
model = Sequential()
model.add(Conv2D(32,(5,5),activation='relu', input_shape=(32,32,3)))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Conv2D(32,(5,5),activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Flatten())
model.add(Dense(1000,activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(500,activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(250,activation='relu'))
model.add(Dense(10,activation='softmax'))
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
hist = model.fit(x_train, y_train_one_hot,
batch_size=256,
epochs=10,
validation_split=0.2 )
model.evaluate(x_test, y_test_one_hot)[1]
plt.plot(hist.history['accuracy'])
plt.plot(hist.history['val_accuracy'])
plt.title('Model Accuracy')
plt.xlabel('epochs')
plt.ylabel('accuracy')
plt.legend(['Train', 'Val'],loc='upper right')
plt.show()
plt.plot(hist.history['loss'])
plt.plot(hist.history['val_loss'])
plt.title('Model Loss')
plt.xlabel('epochs')
plt.ylabel('loss')
plt.legend(['Train', 'Val'],loc='upper right')
plt.show()
Imagenet Colab Link:
Comments