def get_bytes_to_image_callback(image_dims=(<NUM_LIT>, <NUM_LIT>)):
from keras.preprocessing import image<EOL>import numpy as np<EOL>from PIL import Image<EOL>from io import BytesIO<EOL>def preprocess_image_bytes(data_bytes):<EOL><INDENT>"""<STR_LIT>"""<EOL>try:<EOL><INDENT>img = Image.open(BytesIO(data_bytes))  <EOL><DEDENT>except OSError as e:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>img = img.resize(image_dims, Image.ANTIALIAS)  <EOL>x = image.img_to_array(img)  <EOL>x = np.expand_dims(x, axis=<NUM_LIT:0>)  <EOL>return x<EOL><DEDENT>return preprocess_image_bytes<EOL>
Return a callback to process image bytes for ImageNet.