Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Include module turicreate
import turicreate as tc
# Define all painting images annotations with bounding box details (I am showing only 5)
annotations = tc.SArray([
[
{'label': 'painting1', 'type': 'rectangle', 'coordinates': {'height': 725, 'width': 625, 'x': 736, 'y': 636}}
],
[
{'label': 'painting2', 'type': 'rectangle', 'coordinates': {'height': 735, 'width': 661, 'x': 396, 'y': 568}}
],
[
{'label': 'painting3', 'type': 'rectangle', 'coordinates': {'height': 397, 'width': 375, 'x': 640, 'y': 637}}
],
[
{'label': 'painting4', 'type': 'rectangle', 'coordinates': {'height': 512, 'width': 432, 'x': 598, 'y': 618}}
],
[
{'label': 'painting5', 'type': 'rectangle', 'coordinates': {'height': 563, 'width': 519, 'x': 757, 'y': 666}}
]
])
#load images by providing their relative path to the folder
images = tc.SArray([
tc.Image('images/painting1.jpg'),
tc.Image('images/painting2.jpg '),
tc.Image('images/painting3.jpg '),
tc.Image('images/painting4.jpg '),
tc.Image('images/painting5.jpg ')
])
# Merge images and annotations
data = tc.SFrame({'image': images, 'annotations': annotations})
# Make a train-test split
train_data, test_data = data.random_split(0.8)
# Create a model using Turi Create’s object detector API
model = tc.object_detector.create(train_data, max_iterations=1000)
# Save the predictions to an SArray
predictions = model.predict(test_data)
# Evaluate the model and save the results into a dictionary
metrics = model.evaluate(test_data)
# Save the model for later use in Turi Create
model.save('painting.model')
# Export for use in Core ML file to the current directory
model.export_coreml('Painting.mlmodel')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.