Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 12 additions & 66 deletions Deep Learning/Dogs_vs_cats_CNN.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@

# coding: utf-8

# In[37]:


import numpy as np
import random
import pickle
import matplotlib.pyplot as plt
%matplotlib inline
import cv2
import os
from tqdm import tqdm
import tensorflow as tf
from tensorflow import keras
from keras.models import Sequential
from keras.layers import Activation, Dense, Dropout, Flatten, Conv2D, MaxPooling2D
from keras.callbacks import TensorBoard
import time

DIR='C:/Users/Asus/Downloads/ML DATASETS/Dogs Vs Cats/'
CATEGORIES = ['dog', 'cat']
Expand All @@ -18,28 +21,16 @@
for img in tqdm(os.listdir(train_path)):
label = img.split('.')[0]
img_array = cv2.imread(os.path.join(train_path, img), cv2.IMREAD_GRAYSCALE)
plt.imshow(img_array, cmap='gray')
plt.imshow(img_array, cmap='red')
plt.show()
break


# In[38]:


print(img_array)


# In[39]:


new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE), 1)
plt.imshow(new_array, cmap="gray")
plt.imshow(new_array, cmap="red")
plt.show()


# In[40]:


training_data = []

def create_train_data():
Expand All @@ -54,38 +45,16 @@ def create_train_data():
pass

create_train_data()


# In[41]:


print(len(training_data))


# In[42]:


import random
random.shuffle(training_data)


# In[43]:


X=[]
y=[]
for features,labels in training_data:
X.append(features)
y.append(labels)

X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 1)


# In[44]:


import pickle

pickle_out = open("X.pickle", "wb")
pickle.dump(X, pickle_out)
pickle_out.close()
Expand All @@ -94,23 +63,6 @@ def create_train_data():
pickle.dump(y, pickle_out)
pickle_out.close()


# In[45]:


#################################################################


# In[46]:


import tensorflow as tf
from tensorflow import keras
from keras.models import Sequential
from keras.layers import Activation, Dense, Dropout, Flatten, Conv2D, MaxPooling2D
from keras.callbacks import TensorBoard
import time

X = pickle.load(open("X.pickle", "rb"))
y = pickle.load(open("y.pickle", "rb"))

Expand Down Expand Up @@ -140,17 +92,11 @@ def create_train_data():

model.fit(X, y, batch_size=32, epochs=10, validation_split=0.1, callbacks=[tensorboard])


# In[47]:


predict=['Dog', 'Cat']
def prepare(filepath):
image_array=cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)
new_img = cv2.resize(image_array, (IMG_SIZE, IMG_SIZE))
return new_img.reshape(-1, IMG_SIZE, IMG_SIZE, 1)

prediction=model.predict([prepare('D:\250px-Gatto_europeo4.jpg')])
print(predict[int(prediction[0][0])])