ajbrock / Neural-Photo-Editor

A simple interface for editing natural photos with generative neural networks.
MIT License
2.08k stars 197 forks source link

Failed to interpret file IAN_simple.npz as a pickle #10

Closed slavakurilyak closed 7 years ago

slavakurilyak commented 7 years ago

After changing NPE.py to model = IAN(config_path = 'IAN_simple.py', dnn = False), I get:

$ python NPE.py
Loading weights
Traceback (most recent call last):
  File "NPE.py", line 53, in <module>
    model = IAN(config_path = 'IAN_simple.py', dnn = False)
  File "/Users/skurilyak/Documents/dev/testing/Neural-Photo-Editor/API.py", line 30, in __init__
    GANcheckpoints.load_weights(self.weights_fname,params)
  File "/Users/skurilyak/Documents/dev/testing/Neural-Photo-Editor/GANcheckpoints.py", line 39, in load_weights
    param_dict = np.load(fname)
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/npyio.py", line 416, in load
    "Failed to interpret file %s as a pickle" % repr(file))
IOError: Failed to interpret file 'IAN_simple.npz' as a pickle

Any ideas?

ajbrock commented 7 years ago

Hmm, interesting. Do you want to get an MD5 checksum on the npz and make sure it's the same as the one I've got?

78 6a e4 96 55 bc 0c b4 bd 9d 14 d5 83 03 e9 c8

My suspicion is it's something with git-lfs and the way things are cloned/downloaded, but I'm not sure.

slavakurilyak commented 7 years ago

MD5 (IAN_simple.npz) = 2cc64930d6c6c392288dc13b782ed07b

ajbrock commented 7 years ago

Ah, that would appear to be different. Try downloading it from my drive link: https://drive.google.com/open?id=0B3_iVBZsC4GGck5WWWc0R0dvT1U

slavakurilyak commented 7 years ago

After replacing IAN_simple.py, I get:

$ THEANO_FLAGS='exception_verbosity=high' python NPE.py
Loading weights
Compiling Theano Functions
Compiling remaining functions
Running
Traceback (most recent call last):
  File "NPE.py", line 458, in <module>
    Reset()
  File "NPE.py", line 368, in Reset
    Z = np.reshape(model.encode_images(np.asarray([to_tanh(IM)],dtype=np.float32))[0],np.shape(Z))
  File "/Users/skurilyak/Documents/dev/testing/Neural-Photo-Editor/API.py", line 90, in encode_images
    return self.Z_hat_fn(images)
  File "/usr/local/lib/python2.7/site-packages/theano/compile/function_module.py", line 871, in __call__
    storage_map=getattr(self.fn, 'storage_map', None))
  File "/usr/local/lib/python2.7/site-packages/theano/gof/link.py", line 314, in raise_with_op
    reraise(exc_type, exc_value, exc_trace)
  File "/usr/local/lib/python2.7/site-packages/theano/compile/function_module.py", line 859, in __call__
    outputs = self.fn()
ValueError: CorrMM received weight with wrong type.
Apply node that caused the error: CorrMM{(2, 2), (2, 2)}(X, enc_conv1.W)
Toposort index: 22
Inputs types: [TensorType(float32, 4D), TensorType(float64, 4D)]
Inputs shapes: [(1, 3, 64, 64), (128, 3, 5, 5)]
Inputs strides: [(49152, 16384, 256, 4), (600, 200, 40, 8)]
Inputs values: ['not shown', 'not shown']
Outputs clients: [[Elemwise{Composite{((i0 * (i1 + i2)) + (i3 * Abs((i1 + i2))))}}(TensorConstant{(1, 1, 1, 1) of 0.6}, CorrMM{(2, 2), (2, 2)}.0, InplaceDimShuffle{x,0,x,x}.0, TensorConstant{(1, 1, 1, 1) of 0.4})]]

Backtrace when the node is created(use Theano flag traceback.limit=N to make it longer):
  File "NPE.py", line 53, in <module>
    model = IAN(config_path = 'IAN_simple.py', dnn = False)
  File "/Users/skurilyak/Documents/dev/testing/Neural-Photo-Editor/API.py", line 50, in __init__
    self.Z_hat=lasagne.layers.get_output(self.model['l_Z'],{self.model['l_in']:self.X},deterministic=True)
  File "/usr/local/lib/python2.7/site-packages/lasagne/layers/helper.py", line 191, in get_output
    all_outputs[layer] = layer.get_output_for(layer_inputs, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/lasagne/layers/conv.py", line 330, in get_output_for
    conved = self.convolve(input, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/lasagne/layers/conv.py", line 608, in convolve
    filter_flip=self.flip_filters)

Debugprint of the apply node:
CorrMM{(2, 2), (2, 2)} [id A] <TensorType(float32, 4D)> ''
 |X [id B] <TensorType(float32, 4D)>
 |enc_conv1.W [id C] <TensorType(float64, 4D)>

Storage map footprint:
 - enc_fc1.W, Shared Input, Shape: (16384, 1000), ElemSize: 8 Byte(s), TotalSize: 131072000 Byte(s)
 - enc_conv4.W, Shared Input, Shape: (1024, 512, 5, 5), ElemSize: 8 Byte(s), TotalSize: 104857600 Byte(s)
 - enc_conv3.W, Shared Input, Shape: (512, 256, 5, 5), ElemSize: 8 Byte(s), TotalSize: 26214400 Byte(s)
 - enc_conv2.W, Shared Input, Shape: (256, 128, 5, 5), ElemSize: 8 Byte(s), TotalSize: 6553600 Byte(s)
 - enc_mu.W, Shared Input, Shape: (1000, 100), ElemSize: 8 Byte(s), TotalSize: 800000 Byte(s)
 - enc_conv1.W, Shared Input, Shape: (128, 3, 5, 5), ElemSize: 8 Byte(s), TotalSize: 76800 Byte(s)
 - X, Input, Shape: (1, 3, 64, 64), ElemSize: 4 Byte(s), TotalSize: 49152 Byte(s)
 - bnorm4.mean, Shared Input, Shape: (1024,), ElemSize: 8 Byte(s), TotalSize: 8192 Byte(s)
 - bnorm4.gamma, Shared Input, Shape: (1024,), ElemSize: 8 Byte(s), TotalSize: 8192 Byte(s)
 - bnorm4.inv_std, Shared Input, Shape: (1024,), ElemSize: 8 Byte(s), TotalSize: 8192 Byte(s)
 - bnorm4.beta, Shared Input, Shape: (1024,), ElemSize: 8 Byte(s), TotalSize: 8192 Byte(s)
 - bnorm_enc_fc1.mean, Shared Input, Shape: (1000,), ElemSize: 8 Byte(s), TotalSize: 8000 Byte(s)
 - bnorm_enc_fc1.gamma, Shared Input, Shape: (1000,), ElemSize: 8 Byte(s), TotalSize: 8000 Byte(s)
 - bnorm_enc_fc1.inv_std, Shared Input, Shape: (1000,), ElemSize: 8 Byte(s), TotalSize: 8000 Byte(s)
 - bnorm_enc_fc1.beta, Shared Input, Shape: (1000,), ElemSize: 8 Byte(s), TotalSize: 8000 Byte(s)
 - bnorm3.inv_std, Shared Input, Shape: (512,), ElemSize: 8 Byte(s), TotalSize: 4096 Byte(s)
 - bnorm3.beta, Shared Input, Shape: (512,), ElemSize: 8 Byte(s), TotalSize: 4096 Byte(s)
 - bnorm3.mean, Shared Input, Shape: (512,), ElemSize: 8 Byte(s), TotalSize: 4096 Byte(s)
 - bnorm3.gamma, Shared Input, Shape: (512,), ElemSize: 8 Byte(s), TotalSize: 4096 Byte(s)
 - bnorm2.mean, Shared Input, Shape: (256,), ElemSize: 8 Byte(s), TotalSize: 2048 Byte(s)
 - bnorm2.gamma, Shared Input, Shape: (256,), ElemSize: 8 Byte(s), TotalSize: 2048 Byte(s)
 - bnorm2.inv_std, Shared Input, Shape: (256,), ElemSize: 8 Byte(s), TotalSize: 2048 Byte(s)
 - bnorm2.beta, Shared Input, Shape: (256,), ElemSize: 8 Byte(s), TotalSize: 2048 Byte(s)
 - enc_conv1.b, Shared Input, Shape: (128,), ElemSize: 8 Byte(s), TotalSize: 1024 Byte(s)
 - mu_bnorm.mean, Shared Input, Shape: (100,), ElemSize: 8 Byte(s), TotalSize: 800 Byte(s)
 - mu_bnorm.gamma, Shared Input, Shape: (100,), ElemSize: 8 Byte(s), TotalSize: 800 Byte(s)
 - mu_bnorm.inv_std, Shared Input, Shape: (100,), ElemSize: 8 Byte(s), TotalSize: 800 Byte(s)
 - mu_bnorm.beta, Shared Input, Shape: (100,), ElemSize: 8 Byte(s), TotalSize: 800 Byte(s)
 - TensorConstant{-1}, Shape: (), ElemSize: 8 Byte(s), TotalSize: 8.0 Byte(s)
 - TensorConstant{(1, 1, 1, 1) of 0.6}, Shape: (1, 1, 1, 1), ElemSize: 8 Byte(s), TotalSize: 8 Byte(s)
 - TensorConstant{(1, 1, 1, 1) of 0.4}, Shape: (1, 1, 1, 1), ElemSize: 8 Byte(s), TotalSize: 8 Byte(s)
 - TensorConstant{(1, 1) of 0}, Shape: (1, 1), ElemSize: 1 Byte(s), TotalSize: 1 Byte(s)
 TotalSize: 269717145.0 Byte(s) 0.251 GB
 TotalSize inputs: 269717145.0 Byte(s) 0.251 GB
ajbrock commented 7 years ago

Have you set floatX=float32 in your .theanorc (or from the command line if you're on a linux machine)?

slavakurilyak commented 7 years ago

Setting Theano Environment Variable solved the issue. Here are two ways to accomplish this:

Setup Theano floatX Locally (Source: Stackoverflow)

$ THEANO_FLAGS='floatX=float32' python NPE.py

Setup Theano floatX Globally (Source: Theano)

$ echo -e "\n[global]\nfloatX=float32\n" >> ~/.theanorc
$ python NPE.py

Please update README to reflect this issue.

P.S. I'm using MacBook Pro, 2.2Ghz, 15-inch, Mid 2015, 16GB of RAM (Tech Specs)

ajbrock commented 7 years ago

That's a pretty standard Theano flag, and is already in the readme. Glad it worked out!

nebuladream commented 7 years ago

@ajbrock run the code on my mac, get the same problem with @slavakurilyak Loading weights Traceback (most recent call last): File "NPE.py", line 19, in model = IAN(config_path = 'IAN_simple.py', dnn = False) File "/Volumes/Transcend/toutiao/codes/gans/Neural-Photo-Editor/API.py", line 30, in init GANcheckpoints.load_weights(self.weights_fname,params) File "/Volumes/Transcend/toutiao/codes/gans/Neural-Photo-Editor/GANcheckpoints.py", line 39, in load_weights param_dict = np.load(fname) File "/Users/nebula/.local/lib/python2.7/site-packages/numpy/lib/npyio.py", line 429, in load "Failed to interpret file %s as a pickle" % repr(file)) IOError: Failed to interpret file 'IAN_simple.npz' as a pickle

I check the IAN_simple md5, get MD5 (IAN_simple.npz) = 2cc64930d6c6c392288dc13b782ed07b Can you provide me the right IAN_simple.npz file you have given on google driven? It seems exprie

ajbrock commented 7 years ago

The drive mirror of the weight file is linked above, and still works fine for me.