Skip to content

Instantly share code, notes, and snippets.

@b0noI
Last active December 6, 2018 23:31
Show Gist options
  • Select an option

  • Save b0noI/5f578c2f25e3ecd3264be1ab5e660ea0 to your computer and use it in GitHub Desktop.

Select an option

Save b0noI/5f578c2f25e3ecd3264be1ab5e660ea0 to your computer and use it in GitHub Desktop.
from PIL import Image
import numpy as np
import json
import codecs
img = Image.open("image.jpg").resize((240, 240))
img_array=np.array(img)
result = {
"instances":[img_array.tolist()]
}
file_path="/tmp/out.json"
json.dump(result, codecs.open(file_path, 'w', encoding='utf-8'), separators=(',', ':'), sort_keys=True, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment