During inference NaNs are returned
Hi,
@kirilg, @wolffg , I would appreciate your help.
ISSUE
I'm trying to serve my custom model with Tensorflow Serving.
That model should extract embeddings from images.
I am using MobileNet model from Keras framework to extract embeddings.
I get "NaN"s instead of floats during inference:
'{\n "outputs": {\n "outputs": {\n "dtype": "DT_FLOAT",\n "tensorShape": {\n "dim": [\n {\n "size": "1"\n },\n {\n "size": "128"\n }\n ]\n },\n "floatVal": [\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN",\n "NaN"\n ]\n }\n }\n}'
With built-in ResNet50 I had no problem - I've received embedding of floats instead of "NaN"s.
Could you help me please with this issue or suggest what are further steps for debugging (it took me few days to localize the most exact issue)?
Thank you! :)
CONFIGURATION Tensorflow version: 1.3.0 Tensorflow Serving version: 1.3.0 Link to trained model and python scripts: https://goo.gl/2vRTt4
Bazel: Build label: 0.5.4 Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar Build time: Fri Aug 25 10:00:00 2017 (1503655200) Build timestamp: 1503655200 Build timestamp as int: 1503655200
tensorflow_model_server was build with command: bazel build -c opt //tensorflow_serving/model_servers:tensorflow_model_server
I launch Tensorflow Serving server with following command: bazel-bin/tensorflow_serving/model_servers/tensorflow_model_server --enable_batching --port=9001 --model_name=embedder --model_base_path=/home/user/models/
With the best regards, Oleksandr
This is most likely more related to Tensorflow than Tensorflow serving. Can you load your model and run inference in python? If so, you can try to use tensorflow debugger to debug NaNs (https://www.tensorflow.org/programmers_guide/debugger).
@lilao , thank you for advice. I've tried, but for me model can successfully inference using just Tensorflow.
I've also checked fully optimized Tensorflow graph (optimized_graph.pb) - it runs inference and returns floats (as well as Keras Tensorflow model).
In another thread I've seen how to log error (set TF_CPP_MIN_VLOG_LEVEL=1). I've reproduced bug and captured the log (please see log.txt)
Short summary from the log:
2017-09-12 21:59:48.822730: I external/org_tensorflow/tensorflow/core/common_runtime/constant_folding.cc:314] Constant foldable 388 : 568
2017-09-12 21:59:48.825379: I external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1057] Instantiating kernel for node: _SOURCE = NoOp[]()
2017-09-12 21:59:48.825429: I external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1057] Instantiating kernel for node: _SINK = NoOp[]()
2017-09-12 21:59:48.825469: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_FLOAT shape { } allocation_description { requested_bytes: 4 allocator_name: "cpu" ptr: 140719235501728 } } }
2017-09-12 21:59:48.825509: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorDeallocation { allocator_name: "cpu" }
2017-09-12 21:59:48.825522: I external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1057] Instantiating kernel for node: embeddings/l2_normalize/Maximum/y = Const[_output_shapes=[[]], dtype=DT_FLOAT, value=Tensor<type: float shape: [] values: 1e-12>, _device="/job:localhost/replica:0/task:0/cpu:0"]()
2017-09-12 21:59:48.825560: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_FLOAT shape { } allocation_description { requested_bytes: 4 allocator_name: "cpu" ptr: 140719235799008 } } }
2017-09-12 21:59:48.825592: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_INT32 shape { } allocation_description { requested_bytes: 4 allocator_name: "cpu" ptr: 140719235966080 } } }
2017-09-12 21:59:48.825619: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorDeallocation { allocator_name: "cpu" }
2017-09-12 21:59:48.825630: I external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1057] Instantiating kernel for node: embeddings/l2_normalize/Sum/reduction_indices = Const[_output_shapes=[[]], dtype=DT_INT32, value=Tensor<type: int32 shape: [] values: 1>, _device="/job:localhost/replica:0/task:0/cpu:0"]()
2017-09-12 21:59:48.825656: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_INT32 shape { } allocation_description { requested_bytes: 4 allocator_name: "cpu" ptr: 140719235667648 } } }
2017-09-12 21:59:48.825680: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_FLOAT shape { dim { size: 128 } } allocation_description { requested_bytes: 512 allocator_name: "cpu" ptr: 140719235970336 } } }
2017-09-12 21:59:48.825713: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorDeallocation { allocator_name: "cpu" }
2017-09-12 21:59:48.825725: I external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1057] Instantiating kernel for node: dense_1/bias = Const[_output_shapes=[[128]], dtype=DT_FLOAT, value=Tensor<type: float shape: [128] values: 0.22175114 -0.12764968 0.061892822...>, _device="/job:localhost/replica:0/task:0/cpu:0"]()
2017-09-12 21:59:48.825752: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_FLOAT shape { dim { size: 128 } } allocation_description { requested_bytes: 512 allocator_name: "cpu" ptr: 140719235612896 } } }
2017-09-12 21:59:48.825822: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_FLOAT shape { dim { size: 1024 } dim { size: 128 } } allocation_description { requested_bytes: 524288 allocator_name: "cpu" ptr: 140719236049152 } } }
2017-09-12 21:59:48.825879: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorDeallocation { allocator_name: "cpu" }
2017-09-12 21:59:48.825894: I external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1057] Instantiating kernel for node: dense_1/kernel = Const[_output_shapes=[[1024,128]], dtype=DT_FLOAT, value=Tensor<type: float shape: [1024,128] values: [0.74261773 1.2202173 -0.43706125]...>, _device="/job:localhost/replica:0/task:0/cpu:0"]()
2017-09-12 21:59:48.826013: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_FLOAT shape { dim { size: 1024 } dim { size: 128 } } allocation_description { requested_bytes: 524288 allocator_name: "cpu" ptr: 140719236573408 } } }
2017-09-12 21:59:48.826042: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_INT32 shape { dim { size: 2 } } allocation_description { requested_bytes: 8 allocator_name: "cpu" ptr: 140719235971392 } } }
2017-09-12 21:59:48.826056: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorDeallocation { allocator_name: "cpu" }
2017-09-12 21:59:48.826067: I external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1057] Instantiating kernel for node: global_average_pooling2d_1/Mean/reduction_indices = Const[_output_shapes=[[2]], dtype=DT_INT32, value=Tensor<type: int32 shape: [2] values: 1 2>, _device="/job:localhost/replica:0/task:0/cpu:0"]()
2017-09-12 21:59:48.826101: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_INT32 shape { dim { size: 2 } } allocation_description { requested_bytes: 8 allocator_name: "cpu" ptr: 140719235970976 } } }
2017-09-12 21:59:48.826123: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_FLOAT shape { } allocation_description { requested_bytes: 4 allocator_name: "cpu" ptr: 140719235972992 } } }
2017-09-12 21:59:48.826143: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorDeallocation { allocator_name: "cpu" }
2017-09-12 21:59:48.826154: I external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1057] Instantiating kernel for node: conv_pw_13_relu/Const_1 = Const[_output_shapes=[[]], dtype=DT_FLOAT, value=Tensor<type: float shape: [] values: 0>, _device="/job:localhost/replica:0/task:0/cpu:0"]()
2017-09-12 21:59:48.826183: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_FLOAT shape { } allocation_description { requested_bytes: 4 allocator_name: "cpu" ptr: 140719235971552 } } }
2017-09-12 21:59:48.826206: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_INT32 shape { } allocation_description { requested_bytes: 4 allocator_name: "cpu" ptr: 140719235974912 } } }
2017-09-12 21:59:48.826219: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorDeallocation { allocator_name: "cpu" }
2017-09-12 21:59:48.826229: I external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1057] Instantiating kernel for node: conv_pw_13_relu/Const = Const[_output_shapes=[[]], dtype=DT_INT32, value=Tensor<type: int32 shape: [] values: 6>, _device="/job:localhost/replica:0/task:0/cpu:0"]()
2017-09-12 21:59:48.826252: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_INT32 shape { } allocation_description { requested_bytes: 4 allocator_name: "cpu" ptr: 140719235973152 } } }
2017-09-12 21:59:48.826269: I external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1057] Instantiating kernel for node: conv_pw_13_relu/Cast = Cast[DstT=DT_FLOAT, SrcT=DT_INT32, _output_shapes=[[]], _device="/job:localhost/replica:0/task:0/cpu:0"](conv_pw_13_relu/Const)
2017-09-12 21:59:48.826327: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_FLOAT shape { dim { size: 1024 } } allocation_description { requested_bytes: 4096 allocator_name: "cpu" ptr: 140719235585504 } } }
2017-09-12 21:59:48.826359: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorDeallocation { allocator_name: "cpu" }
2017-09-12 21:59:48.826371: I external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1057] Instantiating kernel for node: conv_pw_13_bn/gamma = Const[_output_shapes=[[1024]], dtype=DT_FLOAT, value=Tensor<type: float shape: [1024] values: 5.8470016 5.5798435 5.8278446...>, _device="/job:localhost/replica:0/task:0/cpu:0"]()
2017-09-12 21:59:48.826400: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_FLOAT shape { dim { size: 1024 } } allocation_description { requested_bytes: 4096 allocator_name: "cpu" ptr: 140719235690240 } } }
2017-09-12 21:59:48.826428: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_FLOAT shape { } allocation_description { requested_bytes: 4 allocator_name: "cpu" ptr: 140719235591552 } } }
2017-09-12 21:59:48.826449: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorDeallocation { allocator_name: "cpu" }
2017-09-12 21:59:48.826460: I external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1057] Instantiating kernel for node: conv_pw_13_bn/batchnorm_1/add/y = Const[_output_shapes=[[]], dtype=DT_FLOAT, value=Tensor<type: float shape: [] values: 0.001>, _device="/job:localhost/replica:0/task:0/cpu:0"]()
2017-09-12 21:59:48.826485: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_FLOAT shape { } allocation_description { requested_bytes: 4 allocator_name: "cpu" ptr: 140719235591392 } } }
2017-09-12 21:59:48.826508: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_FLOAT shape { dim { size: 1024 } } allocation_description { requested_bytes: 4096 allocator_name: "cpu" ptr: 140719237097792 } } }
2017-09-12 21:59:48.826540: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorDeallocation { allocator_name: "cpu" }
2017-09-12 21:59:48.826552: I external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1057] Instantiating kernel for node: conv_pw_13_bn/moving_variance = Const[_output_shapes=[[1024]], dtype=DT_FLOAT, value=Tensor<type: float shape: [1024] values: 323.61469 448.00632 427.16183...>, _device="/job:localhost/replica:0/task:0/cpu:0"]()
2017-09-12 21:59:48.826581: I external/org_tensorflow/tensorflow/core/framework/log_memory.cc:35] __LOG_MEMORY__ MemoryLogTensorAllocation { step_id: -6 kernel_name: "Unknown (from Proto)" tensor { dtype: DT_FLOAT shape { dim { size: 1024 } } allocation_description { requested_bytes: 4096 allocator_name: "cpu" ptr: 140719237102528 } } }
2017-09-12 21:59:48.826599: I external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1057] Instantiating kernel for node: conv_pw_13_bn/batchnorm_1/add = Add[T=DT_FLOAT, _output_shapes=[[1024]], _device="/job:localhost/replica:0/task:0/cpu:0"](conv_pw_13_bn/moving_variance, conv_pw_13_bn/batchnorm_1/add/y)
2017-09-12 21:59:48.826651: I external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1057] Instantiating kernel for node: conv_pw_13_bn/batchnorm_1/Rsqrt = Rsqrt[T=DT_FLOAT, _output_shapes=[[1024]], _device="/job:localhost/replica:0/task:0/cpu:0"](conv_pw_13_bn/batchnorm_1/add)
@OleksandrMalinin hi, I am new to python and ML, and I think I have a similar issue to yours. I too am using Mobilnet from keras and receive the below error:
ValueError: Error when checking target: expected conv_pw_13_relu to have 4 dimensions, but got array with shape (7666, 120)
I see you closed this issue, did you figure out what was the issue? what was your solution?
Hi, @O-LA-LA My problem was that I've embedded prewhitening at the beginning of my network that caused ZeroDevisionError and led to Nans during inference.
I suggest you to use tf-debug.
Good luck with that.