Skip to content

Instantly share code, notes, and snippets.

View gregchu's full-sized avatar

Greg Chu gregchu

View GitHub Profile
from StringIO import StringIO
from PIL import Image
def encode_jpeg(img, quality=100):
"""Encode ndarray image into a jpeg
Args:
img: 3D (wxhxRGB) array
quality: jpeg compression quality
"""
s = StringIO()
def predict(model, img, target_size, top_n=3):
"""Run model prediction on image
Args:
model: keras model
img: PIL format image
target_size: (w,h) tuple
top_n: # of top predictions to return
Returns:
np array of predictions
"""
dog
bear
chair
car
keyboard
crate
crib
flagpole
iPod
boat
Person
Car
Bicycle
Bus
Motorbike
Train
Aeroplane
Chair
Bottle
Dining Table
tench, Tinca tinca
goldfish, Carassius auratus
great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias
tiger shark, Galeocerdo cuvieri
hammerhead, hammerhead shark
electric ray, crampfish, numbfish, torpedo
stingray
cock
hen
ostrich, Struthio camelus
@gregchu
gregchu / COCO labels
Last active November 29, 2018 12:56
person
bicycle
car
motorcycle
airplane
bus
train
truck
boat
traffic light