Coder Social home page Coder Social logo

prodigy_ml_03's Introduction

PRODIGY_ML_03

Classify dogs and cats on svm algorithm

import pandas as pd import numpy as np import tensorflow as tf

import warnings warnings.filterwarnings('ignore')

from tensorflow.compat.v1 import ConfigProto from tensorflow.compat.v1 import InteractiveSession

config = ConfigProto() config.gpu_options.per_process_gpu_memory_fraction = 0.6 config.gpu_options.allow_growth = True session = InteractiveSession(config=config)

datagen1 = ImageDataGenerator(rescale=1./255)

test_set = datagen1.flow_from_directory( "../input/cat-and-dog/test_set/test_set", target_size=(64, 64), batch_size=32, class_mode="binary" )

from tensorflow.keras.layers import Conv2D from tensorflow.keras.layers import Dense from tensorflow.keras.regularizers import l2 cnn = tf.keras.models.Sequential() cnn = tf.keras.models.Sequential()cnn.add(tf.keras.layers.Conv2D(filters=32,padding='same',kernel_size=3, activation='relu')) cnn.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2)) cnn.add(tf.keras.layers.Flatten())cnn.add(Dense(1, kernel_regularizer=tf.keras.regularizers.l2(0.01),activation ='linear')) cnn.summary()

cnn.compile(optimizer = 'adam', loss = 'hinge', metrics = ['accuracy']) r=cnn.fit(x = training_set, validation_data = test_set, epochs = 15)

plot the loss

import matplotlib.pyplot as plt plt.plot(r.history['loss'], label='train loss') plt.plot(r.history['val_loss'], label='val loss') plt.legend() plt.show()

plot the accuracy

plt.plot(r.history['accuracy'], label='train acc') plt.plot(r.history['val_accuracy'], label='val acc') plt.legend() plt.show()from tensorflow.keras.models import load_model

cnn.save('./model_rcat_dog.h5') from tensorflow.keras.preprocessing import image test_image = image.load_img('../input/cat-and-dog/training_set/training_set/dogs/dog.1023.jpg', target_size = (64,64)) test_image = image.img_to_array(test_image) test_image=test_image/255 test_image = np.expand_dims(test_image, axis = 0) result = cnn.predict(test_image) if result[0]<0: print("The image classified is cat") else: print("The image classified is dog")if result[0]<0: print("The image classified is cat") else: print("The image classified is dog")

prodigy_ml_03's People

Contributors

nandhini-1402 avatar

Stargazers

S.Dhivya avatar Varshiga P S avatar Harini avatar MONISHA K M avatar Jothika Raja avatar Vaishnavi  N  avatar Hemanth M avatar Shaha avatar Dharshini2124 avatar ARTHI J S avatar  avatar  avatar SHESHANTH R S avatar suwe avatar Rajesh V avatar Sanchana S S avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.