ryankiros / neural-storyteller

A recurrent neural network for generating little stories about images
2.96k stars 539 forks source link

AttributeError: 'collections.OrderedDict' object has no attribute 'iteritems' #26

Open jazoza opened 7 years ago

jazoza commented 7 years ago

Hi, I am running into a dead end with the storyteller already at one of the first steps. After having downloaded all necessary files, and set up the config.py, it still won't generate the first

import generate

gives the following error:

ERROR (theano.sandbox.cuda): Failed to compile cuda_ndarray.cu: libcublas.so.8.0: cannot open shared object file: No such file or directory

but it is still able to proceed (or at least that is how I understand it)

and then

z = generate.load_all()

runs into this error (pasting only the end)

`Loading skip-thoughts...

AttributeError Traceback (most recent call last)

in () ----> 1 z = generate.load_all() /home/zoza/neural-storyteller/generate.py in load_all() 84 print('Loading skip-thoughts...') 85 stv = skipthoughts.load_model(config.paths['skmodels'], ---> 86 config.paths['sktables']) 87 88 # Decoder /home/zoza/neural-storyteller/skipthoughts.py in load_model(path_to_models, path_to_tables) 34 # Load parameters 35 uparams = init_params(uoptions) ---> 36 uparams = load_params(path_to_umodel, uparams) 37 utparams = init_tparams(uparams) 38 bparams = init_params_bi(boptions) /home/zoza/neural-storyteller/skipthoughts.py in load_params(path, params) 173 """ 174 pp = numpy.load(path) --> 175 for kk, vv in params.iteritems(): 176 if kk not in pp: 177 warnings.warn('%s is not in the archive'%kk) AttributeError: 'collections.OrderedDict' object has no attribute 'iteritems'` I am running Python 3.5.2 |Anaconda custom (64-bit) and I have adapted the code (print statements in brackets, cPickle module to pickle) to be able to run it on version 3. Any help on how to fix this is appreciated!
HappyCoderMan commented 7 years ago

Get the Python3 compatible version of skipthoughts.py here: https://github.com/ryankiros/skip-thoughts/pull/53/files

I'm also on Anacnoda x64, and my path_to_skipthoughts looks like this: path_to_skipthoughts = 'C:\neuralstoryteller\skip-thoughts-master\' I have the models in a subfolder of that path named "models", and this works.

You can also just change iteritems() to items() in most of these cases to fix that error.

SundareshPrasanna commented 6 years ago

Hi @ErikOmberg thanks for the Python3 compatible version.. when i try to use the new skip-thought code (py3 compatible one), i get an error message as below:

C:\Users\Dell\Documents\Neural_storyteller\neural_storyteller\romance.npz Loading skip-thoughts... Traceback (most recent call last): File "", line 1, in File "C:\Users\Dell\Documents\Neural_storyteller\neural-storyteller-master\generate.py", line 86, in load_all config.paths['sktables']) TypeError: load_model() takes 0 positional arguments but 2 were given

Can u help me with this? I see that we are passing 2 arguments config.paths['skmodels'], config.paths['sktables'] in the original generate.py.. while in the new skipthought i see load_model does not take any arguments.. so i tried to change it to just stv = skipthoughts.load_model() and got the error:

Loading model parameters... Traceback (most recent call last): File "", line 1, in File "C:\Users\Dell\Documents\Neural_storyteller\neural-storyteller-master\generate.py", line 85, in load_all stv = skipthoughts.load_model() File "C:\Users\Dell\Documents\Neural_storyteller\neural-storyteller-master\skipthoughts.py", line 55, in load_model bparams = load_params(path_to_bmodel, bparams) File "C:\Users\Dell\Documents\Neural_storyteller\neural-storyteller-master\skipthoughts.py", line 259, in load_params pp = numpy.load(path) File "C:\Users\Dell\Anaconda3\envs\tensorflow-gpu\lib\site-packages\numpy\lib\npyio.py", line 412, in load pickle_kwargs=pickle_kwargs) File "C:\Users\Dell\Anaconda3\envs\tensorflow-gpu\lib\site-packages\numpy\lib\npyio.py", line 171, in init _zip = zipfile_factory(fid) File "C:\Users\Dell\Anaconda3\envs\tensorflow-gpu\lib\site-packages\numpy\lib\npyio.py", line 101, in zipfile_factory return zipfile.ZipFile(file, *args, **kwargs) File "C:\Users\Dell\Anaconda3\envs\tensorflow-gpu\lib\zipfile.py", line 1026, in init self._RealGetContents() File "C:\Users\Dell\Anaconda3\envs\tensorflow-gpu\lib\zipfile.py", line 1093, in _RealGetContents raise BadZipFile("File is not a zip file") zipfile.BadZipFile: File is not a zip file

HappyCoderMan commented 6 years ago

You're right - I see that link I posted only had a loadmodel function with no arguments. I didn't use that code directly. I started with the master code, and made some code changes (based on that link) to get my py3 working.

The necessary changes aren't too bad. It's mostly a few "items" change to "iteritems", parenthesis around print statements, etc...

SundareshPrasanna commented 6 years ago

I agree.. but i am getting an error when i do so :( could u help me with the error below

Loading skip-thoughts... Traceback (most recent call last): File "", line 1, in File "C:\Users\Dell\Documents\Neural_storyteller\neural-storyteller-master\generate.py", line 86, in load_all config.paths['sktables']) File "C:\Users\Dell\Documents\Neural_storyteller\neural-storyteller-master\skipthoughts.py", line 39, in load_model bparams = load_params(path_to_bmodel, bparams) File "C:\Users\Dell\Documents\Neural_storyteller\neural-storyteller-master\skipthoughts.py", line 174, in load_params pp = numpy.load(path) File "C:\Users\Dell\Anaconda3\envs\tensorflow-gpu\lib\site-packages\numpy\lib\npyio.py", line 412, in load pickle_kwargs=pickle_kwargs) File "C:\Users\Dell\Anaconda3\envs\tensorflow-gpu\lib\site-packages\numpy\lib\npyio.py", line 171, in init _zip = zipfile_factory(fid) File "C:\Users\Dell\Anaconda3\envs\tensorflow-gpu\lib\site-packages\numpy\lib\npyio.py", line 101, in zipfile_factory return zipfile.ZipFile(file, *args, **kwargs) File "C:\Users\Dell\Anaconda3\envs\tensorflow-gpu\lib\zipfile.py", line 1026, in init self._RealGetContents() File "C:\Users\Dell\Anaconda3\envs\tensorflow-gpu\lib\zipfile.py", line 1093, in _RealGetContents raise BadZipFile("File is not a zip file") zipfile.BadZipFile: File is not a zip file

HappyCoderMan commented 6 years ago

Please check your bi_skip.npz file. It may be corrupt or missing if the error says it's not a valid zip file. My code makes that file name like this: path_to_bmodel = path_to_models + 'bi_skip.npz' Mine has this size: 289,340,074 bytes Mine is in this folder: ./models/ I have a bi_skip.npz.pkl file at the same path that is 689 bytes.

The config.py sets the relative path like this:

Skip-thoughts

paths['skmodels'] = './models/' paths['sktables'] = './models/'

SundareshPrasanna commented 6 years ago

Thanks a lot @ErikOmberg .. i didn't notice that my file was corrupted.. i have one question tho wrt resize in generate.py

line 154: im = skimage.transform.resize(im, (256, w*256/h), preserve_range=True) here, there is a possibility that the number won't end up as integer.. so should we add int() to round it up?

HappyCoderMan commented 6 years ago

Yes, I made that change too: int(w*256/h)

SundareshPrasanna commented 6 years ago

Thanks @ErikOmberg .. I've raised a new issue #37 i was wondering if u could help me with that or have u faced similar issues while running your codes.