Skip to content

Instantly share code, notes, and snippets.

View karthick965938's full-sized avatar
🎯
Focusing

Karthick Nagarajan karthick965938

🎯
Focusing
View GitHub Profile
from detecto import core, utils, visualize
# Load you image
image = utils.read_image('cat.jpg')
model = core.Model.load('cat_model_weights', ['cat'])
labels, boxes, scores = model.predict_top(image)
##Test your Image
visualize.show_labeled_image(image, boxes, labels)
##Test your Video
# visualize.detect_video(model, 'cat.mp4', 'output.avi')
##Live Detection
from detecto import core, utils, visualize
image = utils.read_image('apple.jpg')
#Initialized a pre-trained model
model = core.Model()
labels, boxes, scores = model.predict_top(image)
visualize.show_labeled_image(image, boxes, labels)
@karthick965938
karthick965938 / save_model.py
Last active May 11, 2020 12:35
Save your model file on google colab
model.save('model_weights.pth')
#you can save your model using above file
model = core.Model.load('model_weights.pth', ['alien', 'bat', 'witch'])
@karthick965938
karthick965938 / test_model.py
Last active May 11, 2020 12:39
Test your model on google colab for detecto
# 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])
@karthick965938
karthick965938 / prepare_model.py
Last active May 11, 2020 11:26
Python code for prepare object detection model
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)
@karthick965938
karthick965938 / cloab.py
Created May 10, 2020 19:25
Install detecto on google cloab :)
import os
from google.colab import drive
drive.mount('/content/drive')
os.chdir('/content/drive/My Drive/object_detection')
!pip install detecto
@karthick965938
karthick965938 / image_process.py
Last active May 10, 2020 09:59
We can using 'Download All Images' chrome extentions to get images from the google. Here i have shared some images process code
#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()
@karthick965938
karthick965938 / convert_image_resolution.py
Last active May 9, 2020 13:08
Python script for convert image resolution
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)
@karthick965938
karthick965938 / remove_png_image.py
Last active September 12, 2021 16:23
Remove PNG images into the directory
import glob
import pathlib
for file in glob.glob('frames/*.png'):
path = pathlib.Path(file)
path.unlink()
@karthick965938
karthick965938 / video_to_image.py
Last active May 23, 2021 20:01
Create images into the video
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)