BrandonSmithJ / MDN

Mixture Density Network for water constituent estimation
GNU General Public License v3.0
39 stars 34 forks source link

Issue with setup: "zipfile.BadZipFile: File is not a zip file" #9

Closed sentinel3 closed 2 years ago

sentinel3 commented 2 years ago

Hi Brandon, great tool and excited to see this work accompanying the recent RSE publication to public! I tried to setup this code on my local Linux machine (cloud, Ubuntu20.04 VM), but have some issue with setup. I used conda to create an environment: requirements_cz.txt

when use the simple example with random data you provided in the introduction page, I run my test script: python3 -m test.py and recieved the following error:

  File "<stdin>", line 1, in <module>
  File "../MDN/product_estimation.py", line 174, in image_estimates
    estimate = function(im_data, sensor=sensor, **kwargs) if im_data.size else np.zeros((0, 1))
  File "../MDN/product_estimation.py", line 138, in apply_model
    preds, idxs = get_estimates(args, x_test=x_test)
  File "../MDN/product_estimation.py", line 45, in get_estimates
    model_path = generate_config(args, create=x_train is not None)  
  File "../MDN/utils.py", line 348, in generate_config
    uncompress(folder) # Unzip the archive if necessary
  File "../MDN/utils.py", line 107, in uncompress
    with zipfile.ZipFile(path.with_suffix('.zip'), 'r') as zf:
  File "/home/user/anaconda3/envs/MDN/lib/python3.8/zipfile.py", line 1269, in __init__
    self._RealGetContents()
  File "/home/user/anaconda3/envs/MDN/lib/python3.8/zipfile.py", line 1336, in _RealGetContents
    raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file

any clue?

Chui Zeng

my test.py content as below:

from MDN import image_estimates, get_tile_data, get_sensor_bands
sensor ="OLCI"  # "<OLI, MSI, OLCI, or HICO>"
# Or, with just random data:
import numpy as np 
random_data = np.random.rand(3, 3, len(get_sensor_bands(sensor)))
chla, idxs  = image_estimates(random_data, sensor=sensor)
BrandonSmithJ commented 2 years ago

Sure, that error seems to indicate that there's something wrong with the zip file which store the OLCI model you're trying to use. Can you tell me what the contents of the MDN/Weights/OLCI/ folder is? There should be two zip files in it - can you tell me the MD5 hashes of those two zips?

Also, you shouldn't need to use the '-m' flag when running test.py, assuming your folder structure looks like:

Project_folder/
    test.py
    MDN/
        ...

In other words, test.py should be on the same directory level as the MDN folder, rather than inside of it. Then you can just run 'python test.py'.

sentinel3 commented 2 years ago

Thank you for the response. problem solved, the pre-trained neural network models in all Weights subfolders are failed to download using git clone ..., but need to be manually downloaded and updated. Thank you for the comments on file structure, previously has the relative path import issue, later figured out. Best, Chui