Download library/imageLoad.py from chhetri123/caption_generation_transformer: direct link, hf CLI and curl.
- Browser
- Download file 602 Bytes
-
https://huggingface.co/spaces/chhetri123/caption_generation_transformer/resolve/main/library/imageLoad.py
- Command line
-
hf download hf://spaces/chhetri123/caption_generation_transformer/library/imageLoad.py
-
curl -L -o imageLoad.py https://huggingface.co/spaces/chhetri123/caption_generation_transformer/resolve/main/library/imageLoad.py
602 Bytes
| import tensorflow as tf | |
| def load_image(image_path): | |
| img = tf.io.read_file(image_path) | |
| img = tf.image.decode_jpeg(img, channels=3) | |
| img = tf.image.resize(img, (299, 299)) | |
| img = tf.keras.applications.inception_v3.preprocess_input(img) | |
| return img, image_path | |
| # Feature extraction | |
| image_model = tf.keras.applications.InceptionV3(include_top=False, | |
| weights='imagenet') | |
| new_input = image_model.input | |
| hidden_layer = image_model.layers[-1].output | |
| image_features_extract_model = tf.keras.Model(new_input, hidden_layer) | |
| # Tokenizer | |