Download utils/image_preprocessing.py from Chandu06/dermai: direct link, hf CLI and curl.
- Browser
- Download file 358 Bytes
-
https://huggingface.co/spaces/Chandu06/dermai/resolve/main/utils/image_preprocessing.py
- Command line
-
hf download hf://spaces/Chandu06/dermai/utils/image_preprocessing.py
-
curl -L -o image_preprocessing.py https://huggingface.co/spaces/Chandu06/dermai/resolve/main/utils/image_preprocessing.py
358 Bytes
| from PIL import Image | |
| import numpy as np | |
| def preprocess_image(image_file): | |
| """ | |
| Convert uploaded image to model input format. | |
| """ | |
| image = Image.open(image_file) | |
| image = image.convert("RGB") | |
| image = image.resize((224, 224)) | |
| image = np.array(image).astype("float32") | |
| image = np.expand_dims(image, axis=0) | |
| return image |