Skip to content

Instantly share code, notes, and snippets.

@zabir-nabil
Created June 3, 2020 17:29
Show Gist options
  • Save zabir-nabil/2f72d9e909b084e88df10a76204cddb7 to your computer and use it in GitHub Desktop.
Save zabir-nabil/2f72d9e909b084e88df10a76204cddb7 to your computer and use it in GitHub Desktop.
# A procedure which decodes base64 image, runs some machine learning model/ operation(s) (in our case we'll just return the mean of the pixel value)
import numpy as np
import base64
import zlib
def predict(b64img_compressed, w, h):
b64decoded = base64.b64decode(b64img_compressed)
decompressed = b64decoded #zlib.decompress(b64decoded)
imgarr = np.frombuffer(decompressed, dtype=np.uint8).reshape(w, h, -1)
return imgarr.shape[2], np.mean(imgarr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment