I have a question on how to load models weight if the .h5 file is inside the zip file. I am intended to load my machine learning model without extracting the zip file. I have a zip file called ‘model.zip’ now, and inside has ‘model.json’ and ‘model.h5’
I first use the below method to call the json file and it works:
archive = ZipFile(request.data['modelfile']) for file in archive.infolist(): ext = file.filename.split('.')[-1] if ext == 'h5': model_h5_file = archive.open(file) elif ext == 'json': model_json_file = archive.open(file) loaded_model = model_from_json(model_json_file.read())
I use the same way to open the h5 file, but it turns out error:
loaded_model.load_weights(model_h5_file) AttributeError: 'ZipExtFile' object has no attribute 'endswith'
What should I do if I want to use straightly load the weights from the zip file without extracting it, since it will be done in the backend…
Source: Python Questions