ryankiros / neural-storyteller

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

Models adjust in config.py #34

Open quintendewilde opened 7 years ago

quintendewilde commented 7 years ago

In this repo and in Source Ai_Writer both config.py have

# Skip-thoughts
paths['skmodels'] = '/u/rkiros/public_html/models/'
paths['sktables'] = '/u/rkiros/public_html/models/'

I've adjusted all other entrees in the file as well as in the skiptoughts.py.

But here I don't know to what type of file or model to refer to? And were to download these?

I think if I have these I finally will be able to make it work.

ADDENDA

When I run the script example, this is the error received.

<ipython-input-8-5af402f414c9> in <module>()
      1 import generate
----> 2 z = generate.load_all()
      3 generate.story(z, './images/ex1.jpg')

generate.pyc in load_all()
     84     print 'Loading skip-thoughts...'
     85     stv = skipthoughts.load_model(config.paths['skmodels'],
---> 86                                   config.paths['sktables'])
     87 
     88     # Decoder

/home/quinten/Documents/AI_Writer/skipthoughts.py in load_model(path_to_models, path_to_tables)
     27 
     28     # Load model options
---> 29     with open('%s.pkl'%path_to_umodel, 'rb') as f:
     30         uoptions = pkl.load(f)
     31     with open('%s.pkl'%path_to_bmodel, 'rb') as f:

IOError: [Errno 2] No such file or directory: '/u/rkiros/public_html/models//home/quinten/Documents/AI_Writer/data/uni_skip.npz.pkl'

And this is the skipthoughts.py

[def load_model(path_to_models, path_to_tables):
    """
    Load the model with saved tables
    """
    path_to_umodel =  '/home/quinten/Documents/AI_Writer/data/uni_skip.npz.pkl'
    path_to_bmodel =  '/home/quinten/Documents/AI_Writer/data/bi_skip.npz.pkl'

    # Load model options
    with open('%s.pkl'%path_to_umodel, 'rb') as f:
        uoptions = pkl.load(f)
    with open('%s.pkl'%path_to_bmodel, 'rb') as f:
        boptions = pkl.load(f)

    # Load parameters
    uparams = init_params(uoptions)
    uparams = load_params(path_to_umodel, uparams)
    utparams = init_tparams(uparams)
    bparams = init_params_bi(boptions)
    bparams = load_params(path_to_bmodel, bparams)
    btparams = init_tparams(bparams)

    # Extractor functions
    embedding, x_mask, ctxw2v = build_encoder(utparams, uoptions)
    f_w2v = theano.function([embedding, x_mask], ctxw2v, name='f_w2v')
    embedding, x_mask, ctxw2v = build_encoder_bi(btparams, boptions)
    f_w2v2 = theano.function([embedding, x_mask], ctxw2v, name='f_w2v2')

    # Tables
    utable, btable = load_tables(path_to_tables)

    # Store everything we need in a dictionary
    model = {}
    model['uoptions'] = uoptions
    model['boptions'] = boptions
    model['utable'] = utable
    model['btable'] = btable
    model['f_w2v'] = f_w2v
    model['f_w2v2'] = f_w2v2

    return model

def load_tables(path_to_tables):
    """
    Load the tables
    """
    words = []
    utable = numpy.load(path_to_tables + '/home/quinten/Documents/AI_Writer/data/utable.npy')
    btable = numpy.load(path_to_tables + '/home/quinten/Documents/AI_Writer/data/btable.npy')
    f = open(path_to_tables + '/home/quinten/Documents/AI_Writer/data/dictionary.txt', 'rb')
    for line in f:
        words.append(line.decode('utf-8').strip())
    f.close()
    utable = OrderedDict(zip(words, utable))
    btable = OrderedDict(zip(words, btable))
    return utable, btable](url)

And this is the config.py


# Skip-thoughts
paths['skmodels'] = '/home/quinten/Documents/AI_Writer/data/uni_skip.npz.pkl'
paths['sktables'] = '/home/quinten/Documents/AI_Writer/data/bi_skip.npz.pkl'

# Decoder
paths['decmodel'] = '/home/quinten/Documents/AI_Writer/data/romance.npz'
paths['dictionary'] = '/home/quinten/Documents/AI_Writer/data/romance_dictionary.pkl'

# Image-sentence embedding
paths['vsemodel'] = '/home/quinten/Documents/AI_Writer/data/coco_embedding.npz'

# VGG-19 convnet
paths['vgg'] = '/home/quinten/Documents/AI_Writer/data/vgg19.pkl'
paths['pycaffe'] = '/u/yukun/Projects/caffe-run/python' => I also don't know what has to come here
paths['vgg_proto_caffe'] = '/home/quinten/Documents/AI_Writer/data/VGG_ILSVRC_19_layers_deploy.prototxt'
paths['vgg_model_caffe'] = '/home/quinten/Documents/AI_Writer/data/VGG_ILSVRC_19_layers.caffemodel'

# COCO training captions
paths['captions'] = '/home/quinten/Documents/AI_Writer/data/coco_train_caps.txt'

# Biases
paths['negbias'] = '/home/quinten/Documents/AI_Writer/data/caption_style.npy'
paths['posbias'] = '/home/quinten/Documents/AI_Writer/data/romance_style.npy'

I'm seeing an old entry and the one I putted in. I've deleted .pyc and retried, still the same output.

cuuupid commented 7 years ago

The skmodels and sktables keys need to refer to model directories, which you download from skipthoughts repo (see README or just go to @ryankiros skipthoughts repo and run the snippet of wgets).

e.g. a possible config.py for those two keys:

# Skip-thoughts
paths['skmodels'] = '../models/'
paths['sktables'] = '../models/'

The wget snippet can be found here.

Pasting here for quick use:

wget http://www.cs.toronto.edu/~rkiros/models/dictionary.txt
wget http://www.cs.toronto.edu/~rkiros/models/utable.npy
wget http://www.cs.toronto.edu/~rkiros/models/btable.npy
wget http://www.cs.toronto.edu/~rkiros/models/uni_skip.npz
wget http://www.cs.toronto.edu/~rkiros/models/uni_skip.npz.pkl
wget http://www.cs.toronto.edu/~rkiros/models/bi_skip.npz
wget http://www.cs.toronto.edu/~rkiros/models/bi_skip.npz.pkl

You'll want to do this under a new directory, e.g. I did mine in ../models/.

quintendewilde commented 6 years ago

Could you tell me what I have to put here?

paths['pycaffe'] = '/u/yukun/Projects/caffe-run/python' I'm trying to run this on a docker theano/lasagna image

venky1286 commented 5 years ago

how to install pycaffe exactly could any one please tell me

venky1286 commented 5 years ago

paths['pycaffe'] = '/u/yukun/Projects/caffe-run/python'