Question regarding to opening .h5 file in zip file [python]

  keras, python, tensorflow, zip

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 ‘’ 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(['modelfile'])
    for file in archive.infolist(): 
        ext = file.filename.split('.')[-1]
        if ext == 'h5':
            model_h5_file =
        elif ext == 'json':
            model_json_file =

    loaded_model = model_from_json(

I use the same way to open the h5 file, but it turns out error:

    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