Skip to content

Instantly share code, notes, and snippets.

@johnolafenwa
Created April 27, 2018 04:41
Show Gist options
  • Save johnolafenwa/557486516ee95b70c537033c0d2ffdae to your computer and use it in GitHub Desktop.
Save johnolafenwa/557486516ee95b70c537033c0d2ffdae to your computer and use it in GitHub Desktop.
if __name__ == "__main__":
imagefile = "image.png"
imagepath = os.path.join(os.getcwd(), imagefile)
# Donwload image if it doesn't exist
if not os.path.exists(imagepath):
data = requests.get(
"https://github.com/OlafenwaMoses/ImageAI/raw/master/images/3.jpg", stream=True)
with open(imagepath, "wb") as file:
shutil.copyfileobj(data.raw, file)
del data
index_file = "class_index_map.json"
indexpath = os.path.join(os.getcwd(), index_file)
# Donwload class index if it doesn't exist
if not os.path.exists(indexpath):
data = requests.get('https://github.com/OlafenwaMoses/ImageAI/raw/master/imagenet_class_index.json')
with open(indexpath, "w", encoding="utf-8") as file:
file.write(data.text)
class_map = json.load(open(indexpath))
# run prediction function annd obtain prediccted class index
index = predict_image(imagepath)
prediction = class_map[str(index)][1]
print("Predicted Class ", prediction)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment