sagieppel / Fully-convolutional-neural-network-FCN-for-semantic-segmentation-Tensorflow-implementation

68 stars 40 forks source link

inference.py issues? #2

Closed mengyun0829 closed 6 years ago

mengyun0829 commented 6 years ago

I trained your model at Anaconda and then use inference.py but failed. The errors is follwing:

runfile('C:/Users/myzhang/FCN/FCN_Tensorflow/Inference.py', wdir='C:/Users/myzhang/FCN/FCN_Tensorflow') npy file loaded build model started WARNING:tensorflow:From C:\Users\myzhang\FCN\FCN_Tensorflow\BuildNetVgg16.py:110: calling argmax (from tensorflow.python.ops.math_ops) with dimension is deprecated and will be removed in a future version. Instructions for updating: Use the axis argument instead FCN model built Setting up Saver... INFO:tensorflow:Restoring parameters from logs/model.ckpt-100000 Traceback (most recent call last):

File "", line 1, in runfile('C:/Users/myzhang/FCN/FCN_Tensorflow/Inference.py', wdir='C:/Users/myzhang/FCN/FCN_Tensorflow')

File "C:\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile execfile(filename, namespace)

File "C:\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/myzhang/FCN/FCN_Tensorflow/Inference.py", line 81, in main()#Run script

File "C:/Users/myzhang/FCN/FCN_Tensorflow/Inference.py", line 50, in main saver.restore(sess, ckpt.model_checkpoint_path)

File "C:\anaconda3\lib\site-packages\tensorflow\python\training\saver.py", line 1666, in restore {self.saver_def.filename_tensor_name: save_path})

File "C:\anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 889, in run run_metadata_ptr)

File "C:\anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1120, in _run feed_dict_tensor, options, run_metadata)

File "C:\anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1317, in _do_run options, run_metadata)

File "C:\anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1336, in _do_call raise type(e)(node_def, op, message)

InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [1,1,4096,2] rhs shape= [1,1,4096,4] [[Node: save/Assign_2 = Assign[T=DT_FLOAT, _class=["loc:@W8"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](W8, save/RestoreV2_2)]]

Caused by op 'save/Assign_2', defined at: File "C:\anaconda3\lib\site-packages\spyder\utils\ipython\start_kernel.py", line 245, in main() File "C:\anaconda3\lib\site-packages\spyder\utils\ipython\start_kernel.py", line 241, in main kernel.start() File "C:\anaconda3\lib\site-packages\ipykernel\kernelapp.py", line 477, in start ioloop.IOLoop.instance().start() File "C:\anaconda3\lib\site-packages\zmq\eventloop\ioloop.py", line 177, in start super(ZMQIOLoop, self).start() File "C:\anaconda3\lib\site-packages\tornado\ioloop.py", line 888, in start handler_func(fd_obj, events) File "C:\anaconda3\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper return fn(*args, kwargs) File "C:\anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 440, in _handle_events self._handle_recv() File "C:\anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 472, in _handle_recv self._run_callback(callback, msg) File "C:\anaconda3\lib\site-packages\zmq\eventloop\zmqstream.py", line 414, in _run_callback callback(*args, *kwargs) File "C:\anaconda3\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper return fn(args, kwargs) File "C:\anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 283, in dispatcher return self.dispatch_shell(stream, msg) File "C:\anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 235, in dispatch_shell handler(stream, idents, msg) File "C:\anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 399, in execute_request user_expressions, allow_stdin) File "C:\anaconda3\lib\site-packages\ipykernel\ipkernel.py", line 196, in do_execute res = shell.run_cell(code, store_history=store_history, silent=silent) File "C:\anaconda3\lib\site-packages\ipykernel\zmqshell.py", line 533, in run_cell return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs) File "C:\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2698, in run_cell interactivity=interactivity, compiler=compiler, result=result) File "C:\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2808, in run_ast_nodes if self.run_code(code, result): File "C:\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in runfile('C:/Users/myzhang/FCN/FCN_Tensorflow/Inference.py', wdir='C:/Users/myzhang/FCN/FCN_Tensorflow') File "C:\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile execfile(filename, namespace) File "C:\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile exec(compile(f.read(), filename, 'exec'), namespace) File "C:/Users/myzhang/FCN/FCN_Tensorflow/Inference.py", line 81, in main()#Run script File "C:/Users/myzhang/FCN/FCN_Tensorflow/Inference.py", line 45, in main saver = tf.train.Saver() File "C:\anaconda3\lib\site-packages\tensorflow\python\training\saver.py", line 1218, in init self.build() File "C:\anaconda3\lib\site-packages\tensorflow\python\training\saver.py", line 1227, in build self._build(self._filename, build_save=True, build_restore=True) File "C:\anaconda3\lib\site-packages\tensorflow\python\training\saver.py", line 1263, in _build build_save=build_save, build_restore=build_restore) File "C:\anaconda3\lib\site-packages\tensorflow\python\training\saver.py", line 751, in _build_internal restore_sequentially, reshape) File "C:\anaconda3\lib\site-packages\tensorflow\python\training\saver.py", line 439, in _AddRestoreOps assign_ops.append(saveable.restore(tensors, shapes)) File "C:\anaconda3\lib\site-packages\tensorflow\python\training\saver.py", line 160, in restore self.op.get_shape().is_fully_defined()) File "C:\anaconda3\lib\site-packages\tensorflow\python\ops\state_ops.py", line 276, in assign validate_shape=validate_shape) File "C:\anaconda3\lib\site-packages\tensorflow\python\ops\gen_state_ops.py", line 56, in assign use_locking=use_locking, name=name) File "C:\anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "C:\anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 2956, in create_op op_def=op_def) File "C:\anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 1470, in init self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [1,1,4096,2] rhs shape= [1,1,4096,4] [[Node: save/Assign_2 = Assign[T=DT_FLOAT, _class=["loc:@W8"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](W8, save/RestoreV2_2)]]

sagieppel commented 6 years ago

The number of classes in the net you trained is not consistent with the number of classes in the net you defined in the inference file (2 vs 4). Make sure NUM_CLASSES in inference.py is same as the one you used during training.

mengyun0829 commented 6 years ago

Problem solved, thank you so much!