ryankiros / visual-semantic-embedding

Implementation of the image-sentence embedding method described in "Unifying Visual-Semantic Embeddings with Multimodal Neural Language Models"
Other
426 stars 126 forks source link

run train.py #9

Open chirstinaFan opened 6 years ago

chirstinaFan commented 6 years ago

When I run train.trainer() .here are much mistake.Can you meet this problem?

Building model Building f_log_probs... Done Building f_cost... Done Building sentence encoder Building image encoder Building f_grad... Building optimizers...Traceback (most recent call last): File "/Applications/PyCharm.app/Contents/helpers/pydev/pydev_run_in_console.py", line 53, in run_file pydev_imports.execfile(file, globals, locals) # execute the script File "/Users/jiapei.fjp/Documents/python_project/vsepp/visual-semantic-embedding/run.py", line 9, in train.trainer() File "/Users/jiapei.fjp/Documents/python_project/vsepp/visual-semantic-embedding/train.py", line 154, in trainer f_grad_shared, f_update = eval(optimizer)(lr, tparams, grads, inps, cost) File "/Users/jiapei.fjp/Documents/python_project/vsepp/visual-semantic-embedding/optim.py", line 39, in adam f_update = theano.function([lr], [], updates=updates, on_unused_input='ignore', profile=False) File "/Users/jiapei.fjp/venv/download_urls/lib/python2.7/site-packages/theano/compile/function.py", line 317, in function output_keys=output_keys) File "/Users/jiapei.fjp/venv/download_urls/lib/python2.7/site-packages/theano/compile/pfunc.py", line 449, in pfunc no_default_updates=no_default_updates) File "/Users/jiapei.fjp/venv/download_urls/lib/python2.7/site-packages/theano/compile/pfunc.py", line 208, in rebuild_collect_shared raise TypeError(err_msg, err_sug)

pjxhhhh commented 5 years ago

Loading dataset Creating dictionary Dictionary size: 1 Building model OrderedDict([('Wemb', Wemb), ('encoder_W', encoder_W), ('encoder_b', encoder_b), ('encoder_U', encoder_U), ('encoder_Wx', encoder_Wx), ('encoder_Ux', encoder_Ux), ('encoder_bx', encoder_bx), ('ff_image_W', ff_image_W), ('ff_image_b', ff_image_b)]) tparams.type = OrderedDict([('Wemb', Wemb), ('encoder_W', encoder_W), ('encoder_b', encoder_b), ('encoder_U', encoder_U), ('encoder_Wx', encoder_Wx), ('encoder_Ux', encoder_Ux), ('encoder_bx', encoder_bx), ('ff_image_W', ff_image_W), ('ff_image_b', ff_image_b)]) Building f_log_probs... Done Building f_cost... Done Building sentence encoder Building image encoder Building f_grad... Building optimizers... 1 Traceback (most recent call last): File "/home/pjx/anaconda3/lib/python3.6/site-packages/theano/compile/pfunc.py", line 193, in rebuild_collect_shared allow_convert=False) File "/home/pjx/anaconda3/lib/python3.6/site-packages/theano/tensor/type.py", line 234, in filter_variable self=self)) TypeError: Cannot convert Type TensorType(float64, matrix) (of Variable Elemwise{add,no_inplace}.0) into Type TensorType(float32, matrix). You can try to manually convert Elemwise{add,no_inplace}.0 into a TensorType(float32, matrix).

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "train.py", line 225, in trainer() File "train.py", line 154, in trainer f_grad_shared, f_update = eval(optimizer)(lr, tparams, grads, inps, cost) File "/home/pjx/Learning/github_projects/visual-semantic-embedding-master/optim.py", line 43, in adam profile=False) File "/home/pjx/anaconda3/lib/python3.6/site-packages/theano/compile/function.py", line 317, in function output_keys=output_keys) File "/home/pjx/anaconda3/lib/python3.6/site-packages/theano/compile/pfunc.py", line 449, in pfunc no_default_updates=no_default_updates) File "/home/pjx/anaconda3/lib/python3.6/site-packages/theano/compile/pfunc.py", line 208, in rebuild_collect_shared raise TypeError(err_msg, err_sug) TypeError: ('An update must have the same type as the original shared variable (shared_var=<TensorType(float32, matrix)>, shared_var.type=TensorType(float32, matrix), update_val=Elemwise{add,no_inplace}.0, update_val.type=TensorType(float64, matrix)).', 'If the difference is related to the broadcast pattern, you can call the tensor.unbroadcast(var, axis_to_unbroadcast[, ...]) function to remove broadcastable dimensions.')

I face the same issue with u now.would you solve it, please?

gurpreet14 commented 5 years ago

In optim.py change gshared to gshared = [theano.shared(p.get_value().astype('float32'), name='%s_grad'%k) for k, p in tparams.items()]

and in the loop that appends values to 'updates' add: m = theano.shared(p.get_value().astype(numpy.float32)) v = theano.shared(p.get_value().astype(numpy.float32))