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 | |
print(labels) | |
print(boxes) | |
print(scores) |
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 | |
# All images and XML files in the same folder | |
dataset = core.Dataset('images/') | |
# Images and XML files in separate folders | |
dataset = core.Dataset('labels/', 'images/') | |
image, target = dataset[0] | |
print(image, target) |
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 matplotlib.pyplot as plt | |
val_dataset = core.Dataset('validation_images/') | |
losses = model.fit(loader, val_dataset, epochs=10, learning_rate=0.001, | |
lr_step_size=5, verbose=True) | |
plt.plot(losses) | |
plt.show() |
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']) |
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
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
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
# 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
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
import os | |
from google.colab import drive | |
drive.mount('/content/drive') | |
os.chdir('/content/drive/My Drive/Detecto Tutorial') | |
!pip install detecto |
NewerOlder