TensorFlowを使用して作成されたカスタム目的関数を使用して、Kerasシーケンシャルモデルのフィット段階で次のエラーが発生します。ValueError:なし値はサポートされていませんTensorflowのKerasカスタム損失関数
File "basicCNN.py", line 110, in <module>
callbacks=[TensorBoard(log_dir="./logs/{}".format(now))])
File "/home/garethjones/.local/lib/python2.7/site-packages/keras/models.py", line 664, in fit
sample_weight=sample_weight)
File "/home/garethjones/.local/lib/python2.7/site-packages/keras/engine/training.py", line 1115, in fit
self._make_train_function()
File "/home/garethjones/.local/lib/python2.7/site-packages/keras/engine/training.py", line 713, in _make_train_function
self.total_loss)
File "/home/garethjones/.local/lib/python2.7/site-packages/keras/optimizers.py", line 391, in get_updates
m_t = (self.beta_1 * m) + (1. - self.beta_1) * g
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/math_ops.py", line 813, in binary_op_wrapper
y = ops.convert_to_tensor(y, dtype=x.dtype.base_dtype, name="y")
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 669, in convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/constant_op.py", line 176, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/constant_op.py", line 165, in constant
tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_util.py", line 360, in make_tensor_proto
raise ValueError("None values not supported.")
マイカスタム関数は、私は、対話型セッションを持っているとき、私はこれを実行することができ、この
def PAI(y_true, y_pred, k):
'''
Args:
y_true (tensor): (batch x numCells)
y_pred (tensor): (batch x numCells)
k: The optimal number of hotspots
area:
Returns:
cfsRatio (tensor): The inverse of the percentage of crimes in hotspots per observation
'''
# Compute total crime for each obs
totalCFS = tf.reduce_sum(y_true, axis=1) # batch x 1
# Flatten for gather
flatTruth = tf.reshape(y_true, [-1]) # 1 x batch * numCells
# Select top candidate cells
_, predHS = tf.nn.top_k(y_true, k)
# Convert indices for gather
predHSFlat = tf.range(0, tf.shape(y_true)[0]) * tf.shape(y_true)[1] + predHS)
# Map hotspot predictions to crimes
hsCFS = tf.gather(flatTruth, predHSFlat)
# Number of crimes commited in hotspots
hsCFSsum = tf.reduce_sum(hsCFS, axis=1) # batch x 1
# Ratio of crimes committed in hotspots and inverted for minimization
cfsRatio = tf.truediv(1.0, tf.truediv(hsCFSsum, totalCFS))
return cfsRatio
です。この関数は、主にこのTensorflowの問題https://github.com/tensorflow/tensorflow/issues/206のコードに依存しています。
私も同様の問題があります。あなたは解決策を見つけましたか? – user2962197