Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CATS VS DOGS (WEEK5)
- !mkdir -p ~/.kaggle
- !cp kaggle.json ~/.kaggle/
- !kaggle datasets download -d salader/dogs-vs-cats
- import zipfile
- zip_ref = zipfile.ZipFile('/content/dogs-vs-cats.zip', 'r')
- zip_ref.extractall('/content')
- zip_ref.close()
- import tensorflow as tf
- from tensorflow import keras
- from keras import Sequential
- from keras.layers import Dense,Conv2D,MaxPooling2D,Flatten,BatchNormalization,Dropout
- # generators
- train_ds = keras.utils.image_dataset_from_directory(
- directory = '/content/train',
- labels='inferred',
- label_mode = 'int',
- batch_size=32,
- image_size=(256,256)
- )
- validation_ds = keras.utils.image_dataset_from_directory(
- directory = '/content/test',
- labels='inferred',
- label_mode = 'int',
- batch_size=32,
- image_size=(256,256)
- )
- # Normalize
- def process(image,label):
- image = tf.cast(image/255. ,tf.float32)
- return image,label
- train_ds = train_ds.map(process)
- validation_ds = validation_ds.map(process)
- # create CNN model
- model = Sequential()
- model.add(Conv2D(32,kernel_size=(3,3),padding='valid',activation='relu',input_shape=(256,256,3)))
- model.add(BatchNormalization())
- model.add(MaxPooling2D(pool_size=(2,2),strides=2,padding='valid'))
- model.add(Conv2D(64,kernel_size=(3,3),padding='valid',activation='relu'))
- model.add(BatchNormalization())
- model.add(MaxPooling2D(pool_size=(2,2),strides=2,padding='valid'))
- model.add(Conv2D(128,kernel_size=(3,3),padding='valid',activation='relu'))
- model.add(BatchNormalization())
- model.add(MaxPooling2D(pool_size=(2,2),strides=2,padding='valid'))
- model.add(Flatten())
- model.add(Dense(128,activation='relu'))
- model.add(Dropout(0.1))
- model.add(Dense(64,activation='relu'))
- model.add(Dropout(0.1))
- model.add(Dense(1,activation='sigmoid'))
- model.summary()
- model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
- history = model.fit(train_ds,epochs=10,validation_data=validation_ds)
- import matplotlib.pyplot as plt
- plt.plot(history.history['accuracy'],color='red',label='train')
- plt.plot(history.history['val_accuracy'],color='blue',label='validation')
- plt.legend()
- plt.show()
- plt.plot(history.history['accuracy'],color='red',label='train')
- plt.plot(history.history['val_accuracy'],color='blue',label='validation')
- plt.legend()
- plt.show()
- plt.plot(history.history['loss'],color='red',label='train')
- plt.plot(history.history['val_loss'],color='blue',label='validation')
- plt.legend()
- plt.show()
- plt.plot(history.history['loss'],color='red',label='train')
- plt.plot(history.history['val_loss'],color='blue',label='validation')
- plt.legend()
- plt.show()
- import cv2
- test_img = cv2.imread('/content/cat.jpg')
- plt.imshow(test_img)
- test_img.shape
- test_img = cv2.resize(test_img,(256,256))
- test_input = test_img.reshape((1,256,256,3))
- model.predict(test_input)
- WEEK-4
- ADDITION/SUBTRACTION
- from tkinter import *
- def Add():
- a=int(t1.get(1.0, "end-1c"))
- b=int(t2.get(1.0, "end-1c"))
- rea.config(text=str(a+b))
- def Sub():
- a=int(t1.get(1.0, "end-1c"))
- b=int(t2.get(1.0, "end-1c"))
- res.config(text=str(abs(a-b)))
- a = Tk()
- a.geometry("500x500")
- a.title("test")
- l1 = Label(a, text = "enter first variable")
- t1 = Text(a, height = 2, width = 10)
- l1.pack()
- t1.pack()
- l2 = Label(a, text = "enter second variable")
- t2 = Text(a, height = 2, width = 10)
- l2.pack()
- t2.pack()
- Button(a,text='Addition',command=Add).pack()
- l3 = Label(a, text = "Result")
- l3.pack()
- rea = Label(a, text = "")
- rea.pack()
- Button(a,text='subtraction',command=Sub).pack()
- l4= Label(a, text = "Result")
- l4.pack()
- res = Label(a, text = "")
- res.pack()
- a.mainloop()
- CONVERSION
- rom tkinter import *
- def convert():
- a=e1.get()
- euros = float(a) / 88.46
- l3.config(text=str(euros))
- a = Tk()
- a.geometry("300x200")
- a.title("convert")
- l1 = Label(a, text = "ENTER AMOUNT IN RUPEES")
- l1.pack()
- e1= Entry(a)
- e1.pack()
- l2=Label(a,text='AMOUNT IN EUROS')
- l2.pack()
- Button(a,text='convert',command=convert).pack()
- l3=Label(a,text='')
- l3.pack()
- a.mainloop()
- STUDENT DETAILS
- import tkinter as tk
- from tkinter import *
- a = Tk()
- a.geometry("600x600")
- a.title("student details")
- l1=Label(a,text='enter your name')
- e1=Entry(a)
- l1.pack()
- e1.pack()
- l2=Label(a,text='enter your roll number')
- e2=Entry(a)
- l2.pack()
- e2.pack()
- l3=Label(a,text='enter your emailID')
- e3=Entry(a)
- l3.pack()
- e3.pack()
- g=Label(a,text='GENDER')
- g.pack()
- ge=StringVar()
- R1 = Radiobutton(a, text="Male", variable=ge, value='Male')
- R1.pack()
- R2 = Radiobutton(a, text="Female", variable=ge, value='Female')
- R2.pack()
- course_label = tk.Label(a, text="Course:")
- course_label.pack()
- course_listbox = tk.Listbox(a)
- course_listbox.insert(1, "B.Tech")
- course_listbox.insert(2, "M.Tech")
- course_listbox.insert(3, "PhD")
- course_listbox.pack()
- br=Label(a,text='CHOOSE BRANCH')
- br.pack()
- b=Listbox(a)
- b.insert(1,'CSE')
- b.insert(2,'CIVIL')
- b.insert(3,'IT')
- b.insert(4,'ECE')
- b.insert(5,'EEE')
- b.pack()
- Button(a,text='SUBMIT').pack()
- a.mainloop()
- WEEK-2
- FROM IMAGE
- import numpy as np
- import cv2
- csc= r"haarcascade_eye.xml"
- csc2= r"haarcascade_frontalface_default.xml"
- face_cascade=cv2.CascadeClassifier(csc2)
- eye_cascade=cv2.CascadeClassifier(csc)
- img=cv2.imread("C:\WEEK2DL\img_1.png")
- gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
- faces = face_cascade.detectMultiScale(gray, 1.3, 10)
- for(x,y,w,h) in faces:
- cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
- roi_gray=gray[y:y+h,x:x+w]
- roi_color=img[y:y+h,x:x+w]
- eyes = eye_cascade.detectMultiScale(roi_gray)
- for (ex,ey,ew,eh) in eyes:
- cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
- cv2.imshow('img',img)
- cv2.waitKey(0)
- cv2.destroyAllWindows()
- from cam
- import cv2
- cap = cv2.VideoCapture(0) # 0 for default camera, change if necessary
- while True:
- ret, frame = cap.read() # read a frame from the camera
- if ret: # if frame is successfully read
- gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # convert to grayscale
- # apply face detection
- face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
- eye_cascade=cv2.CascadeClassifier('haarcascade_eye.xml')
- faces = face_cascade.detectMultiScale(gray, 1.3, 5)
- eyes = eye_cascade.detectMultiScale(gray, 1.3, 5)
- # draw rectangles around detected faces
- for (x, y, w, h) in faces:
- cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
- for (x, y, w, h) in eyes:
- cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
- # show the captured frame
- cv2.imshow('frame', frame)
- # exit the loop if 'q' key is pressed
- if cv2.waitKey(1) & 0xFF == ord('q'):
- break
- cap.release() # release the camera
- cv2.destroyAllWindows() # close all windows
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement