I'm trying to download a style transfer model, and I want to get style bottlenecks from a bunch of images. Here's the code, which I sourced from this site.
style_predict_path = tf.keras.utils.get_file('style_predict.tflite', 'https://tfhub.dev/google/lite-model/magenta/arbitrary-image-stylization-v1-256/int8/prediction/1?lite-format=tflite')
# Function to run style prediction on preprocessed style image.
def run_style_predict(preprocessed_style_image):
# Load the model.
interpreter = tf.lite.Interpreter(model_path=style_predict_path)
# Set model input.
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
interpreter.set_tensor(input_details[0]["index"], preprocessed_style_image)
# Calculate style bottleneck.
interpreter.invoke()
style_bottleneck = interpreter.tensor(
interpreter.get_output_details()[0]["index"]
)()
return style_bottleneck
# Calculate style bottleneck for the preprocessed style image.
style_bottleneck = run_style_predict(preprocessed_style_image)
print('Style Bottleneck Shape:', style_bottleneck.shape)
However, when I try to run the code, I get the following error:
Traceback (most recent call last):
File "C:\Users\(Name)\Documents\Python\image_style_transfer.py", line 119, in <module>
style_bottleneck = run_style_predict(style_image)
File "C:\Users\(Name)\Documents\Python\image_style_transfer.py", line 60, in run_style_predict
interpreter = tf.lite.Interpreter(model_path=style_predict_path)
File "C:\Users\(Name)\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\lite\python\interpreter.py", line 456, in __init__
_interpreter_wrapper.CreateWrapperFromFile(
ValueError: Could not open 'C:\Users\(Name)\.keras\datasets\style_predict.tflite'.
EDIT: This might or might not help, but the MD5 hash of the style_predict.tflite file I get is 01fdaf469369c39e8662fae8662321b6. I used the code here to get the hash.