View detecto.py
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 | |
# 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 |
View detecto_sample.py
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 | |
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) |
View save_model.py
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']) |
View test_model.py
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]) |
View prepare_model.py
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) |
View cloab.py
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 |
View image_process.py
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() |
View convert_image_resolution.py
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) |
View remove_png_image.py
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() |
View video_to_image.py
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) |
NewerOlder