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
dataset=[] | |
testset=[] | |
count=0 | |
for file in os.listdir(directory): | |
path=os.path.join(directory,file) | |
t=0 | |
for im in os.listdir(path): | |
image=load_img(os.path.join(path,im), grayscale=False, color_mode='rgb', target_size=(180,180)) | |
image=img_to_array(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
labels1=to_categorical(labels0) | |
labels=np.array(labels1) | |
data=np.array(data) | |
test=np.array(test) |
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
trainx,testx,trainy,testy=train_test_split(data,labels,test_size=0.2,random_state=44) | |
from tensorflow.keras.utils import normalize | |
trainx = normalize(trainx) | |
testx = normalize(testx) |
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_datagen = ImageDataGenerator(shear_range = 0.2, | |
zoom_range = 0.2, | |
horizontal_flip = True) | |
train_datagen.fit(trainx) | |
train_generator = train_datagen.flow(trainx,trainy,batch_size = 32) |
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(32,(3,3),input_shape = (180,180,3))) | |
model.add(Activation('elu')) | |
model.add(Conv2D(64,(3,3))) | |
model.add(Activation('elu')) | |
model.add(MaxPool2D(pool_size = (2,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
history = model.fit_generator(train_generator, | |
validation_data=(testx,testy), | |
epochs=50, | |
verbose=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
load_img("dog_photos/test/image4.jpg",target_size=(180,180)) |
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
image=load_img("dog_photos/test/image4.jpg",target_size=(100,100)) | |
image=img_to_array(image) | |
image=image/255.0 | |
prediction_image=np.array(image) | |
prediction_image= np.expand_dims(image, axis=0) | |
prediction=model.predict(prediction_image) | |
value=np.argmax(prediction) | |
move_name=mapper(value) |
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
!wget -N "https://cainvas-static.s3.amazonaws.com/media/user_data/AmrutaKoshe/fruits.zip" | |
!unzip -qo fruits.zip |
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
Name=[] | |
for file in os.listdir(directory): | |
Name+=[file] | |
fruit_map = dict(zip(Name, [t for t in range(len(Name))])) | |
print(fruit_map) | |
r_fruit_map=dict(zip([t for t in range(len(Name))],Name)) |