-
-
Save PulkitS01/2e7b26513b9f883944f42cfd3cb7b237 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
img = image.load_img('avengers.jpeg',target_size=(400,400,3)) | |
img = image.img_to_array(img) | |
img = img/255 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train.columns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
img = image.load_img('golmal.jpeg',target_size=(400,400,3)) | |
img = image.img_to_array(img) | |
img = img/255 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
img = image.load_img('GOT.jpg',target_size=(400,400,3)) | |
img = image.img_to_array(img) | |
img = img/255 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import keras | |
from keras.models import Sequential | |
from keras.layers import Dense, Dropout, Flatten | |
from keras.layers import Conv2D, MaxPooling2D | |
from keras.utils import to_categorical | |
from keras.preprocessing import image | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from sklearn.model_selection import train_test_split | |
from tqdm import tqdm | |
%matplotlib inline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test), batch_size=64) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model = Sequential() | |
model.add(Conv2D(filters=16, kernel_size=(5, 5), activation="relu", input_shape=(400,400,3))) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Dropout(0.25)) | |
model.add(Conv2D(filters=32, kernel_size=(5, 5), activation='relu')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Dropout(0.25)) | |
model.add(Conv2D(filters=64, kernel_size=(5, 5), activation="relu")) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Dropout(0.25)) | |
model.add(Conv2D(filters=64, kernel_size=(5, 5), activation='relu')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Dropout(0.25)) | |
model.add(Flatten()) | |
model.add(Dense(128, activation='relu')) | |
model.add(Dropout(0.5)) | |
model.add(Dense(64, activation='relu')) | |
model.add(Dropout(0.5)) | |
model.add(Dense(25, activation='sigmoid')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model.summary() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plt.imshow(X[2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
classes = np.array(train.columns[2:]) | |
proba = model.predict(img.reshape(1,400,400,3)) | |
top_3 = np.argsort(proba[0])[:-4:-1] | |
for i in range(3): | |
print("{}".format(classes[top_3[i]])+" ({:.3})".format(proba[0][top_3[i]])) | |
plt.imshow(img) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
classes = np.array(train.columns[2:]) | |
proba = model.predict(img.reshape(1,400,400,3)) | |
top_3 = np.argsort(proba[0])[:-4:-1] | |
for i in range(3): | |
print("{}".format(classes[top_3[i]])+" ({:.3})".format(proba[0][top_3[i]])) | |
plt.imshow(img) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
classes = np.array(train.columns[2:]) | |
proba = model.predict(img.reshape(1,400,400,3)) | |
top_3 = np.argsort(proba[0])[:-4:-1] | |
for i in range(3): | |
print("{}".format(classes[top_3[i]])+" ({:.3})".format(proba[0][top_3[i]])) | |
plt.imshow(img) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train = pd.read_csv('multi_label_train.csv') # reading the csv file | |
train.head() # printing first five rows of the file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train_image = [] | |
for i in tqdm(range(train.shape[0])): | |
img = image.load_img('Multi_Label_dataset/Images/'+train['Id'][i]+'.jpg',target_size=(400,400,3)) | |
img = image.img_to_array(img) | |
img = img/255 | |
train_image.append(img) | |
X = np.array(train_image) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X.shape |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train['Genre'][2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
y = np.array(train.drop(['Id', 'Genre'],axis=1)) | |
y.shape |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42, test_size=0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment