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('fruit.jpg') | |
model = core.Model() | |
labels, boxes, scores = model.predict_top(image) | |
visualize.show_labeled_image(image, boxes, labels) |
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.mp4', 'frames/', step_size=4) |
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 torch | |
print(torch.cuda.is_available()) |
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/Detecto Tutorial') | |
!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 | |
dataset = core.Dataset('images/') | |
model = core.Model(['alien', 'bat', 'witch']) | |
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 | |
image = utils.read_image('images/image0.jpg') | |
predictions = model.predict(image) | |
# predictions format: (labels, boxes, scores) | |
labels, boxes, scores = predictions | |
# ['alien', 'bat', 'bat'] | |
print(labels) |
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
visualize.show_labeled_image(image, boxes, labels) |
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
visualize.detect_video(model, 'input.mp4', 'output.avi') |
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 torchvision import transforms | |
augmentations = transforms.Compose([ | |
transforms.ToPILImage(), | |
transforms.RandomHorizontalFlip(0.5), | |
transforms.ColorJitter(saturation=0.5), | |
transforms.ToTensor(), | |
utils.normalize_transform(), | |
]) |
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') | |
# ... Later ... | |
model = core.Model.load('model_weights.pth', ['alien', 'bat', 'witch']) |
OlderNewer