cysmith / neural-style-tf

TensorFlow (Python API) implementation of Neural Style
GNU General Public License v3.0
3.11k stars 828 forks source link

--init_frame_type prev throws a value error: "shapes must be equal rank" #74

Open Abh430 opened 5 years ago

Abh430 commented 5 years ago

I am trying to process video frames without optical flow using the prev init frame type argument, but when it gets to the second frame it throws an error reading: Shapes must be equal rank, but are 4 and 3 for 'Assign_3' (op: 'Assign') with input shapes: [1,1080,1920,3], [1080,1920,3].

The full stack trace reads: File "./style-transfer/neural-style-tf-master/neural_style.py", line 858, in <module> main() File "./style-transfer/neural-style-tf-master/neural_style.py", line 854, in main if args.video: render_video() File "./style-transfer/neural-style-tf-master/neural_style.py", line 847, in render_video stylize(content_frame, style_imgs, init_img, frame) File "./style-transfer/neural-style-tf-master/neural_style.py", line 579, in stylize L_temporal = sum_shortterm_temporal_losses(sess, net, frame, init_img) File "./style-transfer/neural-style-tf-master/neural_style.py", line 463, in sum_shortterm_temporal_losses x = sess.run(net['input'].assign([1] + input_img)) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variables.py", line 1493, in assign name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/state_ops.py", line 221, in assign validate_shape=validate_shape) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_state_ops.py", line 61, in assign use_locking=use_locking, name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/util/deprecation.py", line 488, in new_func return func(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 3272, in create_op op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1790, in __init__ control_input_ops) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1629, in _create_c_op raise ValueError(str(e)) ValueError: Shapes must be equal rank, but are 4 and 3 for 'Assign_3' (op: 'Assign') with input shapes: [1,1080,1920,3], [1080,1920,3].

JoanCharmant commented 5 years ago

I am trying to process video frames without optical flow using the prev init frame type argument

If you use the --video parameter it will always try to compensate for motion using optical flow files, independently of the type of frame used to initialize the gradient descent.

If you want to bypass the optical flow altogether and treat the frames individually you should comment out the block of code under # video temporal loss in the stylize function. But then I think it will be essentially the same as calling the entire script in a loop over the input frames.