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 cv2 | |
# Load the cascade | |
#https://github.com/karthick965938/Face-detection/blob/master/haarcascades/haarcascade_frontalface_default.xml | |
face_cascade = cv2.CascadeClassifier('haarcascades/haarcascade_frontalface_default.xml') | |
# To capture video from webcam. | |
cap = cv2.VideoCapture(0) | |
# To use a video file as input | |
while True: | |
# Read the frame | |
_, img = cap.read() |
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 os | |
os.getcwd() | |
collection = "images/cat" | |
for i, filename in enumerate(os.listdir(collection)): | |
print(filename) | |
os.rename(collection + "/" + filename, collection + "/cat" + str(i) + ".jpg") |
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
from detecto.utils import split_video | |
#split_video('video file path', 'image save path', frame size) | |
split_video('images/cat.mp4', 'images/cat/', step_size=10) |
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 glob | |
import pathlib | |
for file in glob.glob('frames/*.png'): | |
path = pathlib.Path(file) | |
path.unlink() |
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
from PIL import Image | |
import os | |
import argparse | |
def rescale_images(directory, size): | |
for img in os.listdir(directory): | |
im = Image.open(directory+img) | |
im_resized = im.resize(size, Image.ANTIALIAS) | |
im_resized.save(directory+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
#Get images from the google | |
#Remove PNG images | |
import glob | |
import pathlib | |
for file in glob.glob('frames/*.png'): | |
path = pathlib.Path(file) | |
path.unlink() | |
#Rename your images files form the image directory | |
import os | |
os.getcwd() |
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 os | |
from google.colab import drive | |
drive.mount('/content/drive') | |
os.chdir('/content/drive/My Drive/object_detection') | |
!pip install detecto |
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
from detecto import core, utils, visualize | |
#mention you dataset path | |
dataset = core.Dataset('images/') | |
#mention you object label here | |
model = core.Model(['cat']) | |
model.fit(dataset) |
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
# Specify the path to your image | |
from detecto import core, utils, visualize | |
image = utils.read_image('animals/cat48.jpg') | |
predictions = model.predict(image) | |
# predictions format: (labels, boxes, scores) | |
labels, boxes, scores = predictions | |
# ['alien', 'bat', 'bat'] | |
print(labels) | |
print(boxes) | |
# tensor([0.9952, 0.9837, 0.5153]) |
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.save('model_weights.pth') | |
#you can save your model using above file | |
model = core.Model.load('model_weights.pth', ['alien', 'bat', 'witch']) |
OlderNewer