我正在尝试将一个用于粗分割的度量与on tensorflow放在一起,以便与keras一起使用:
https://gist.github.com/DSLituiev/1adcc94b7e4e2b1861d39bbbc2db7307
我读了this issue,这表明我必须使用局部变量初始值设定项,但我仍然得到例外:
Caused by op 'metrics/accuracy_per_channel/accuracy/AssignAdd', defined at:
File "segm_test.py", line 96, in <module>
metrics=[accuracy_per_channel],
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/keras/models.py", line 784, in compile
**kwargs)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/keras/engine/training.py", line 924, in compile
handle_metrics(output_metrics)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/keras/engine/training.py", line 921, in handle_metrics
mask=masks[i])
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/keras/engine/training.py", line 450, in weighted
score_array = fn(y_true, y_pred)
File "segm_test.py", line 89, in accuracy_per_channel
return metric_per_channel_tf(x,y, nch=2, metric=tf.metrics.accuracy)
File "segm_test.py", line 34, in metric_per_channel_tf
_, prec_ = metric(label_channel, pred_channel)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/metrics_impl.py", line 411, in accuracy
updates_collections, name or 'accuracy')
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/metrics_impl.py", line 344, in mean
update_total_op = state_ops.assign_add(total, math_ops.reduce_sum(values))
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/state_ops.py", line 239, in assign_add
ref, value, use_locking=use_locking, name=name)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_state_ops.py", line 71, in assign_add
use_locking=use_locking, name=name)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
op_def=op_def)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2506, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1269, in __init__
self._traceback = _extract_stack()
FailedPreconditionError (see above for traceback): Attempting to use uninitialized value metrics/accuracy_per_channel/accuracy/total
[[Node: metrics/accuracy_per_channel/accuracy/AssignAdd = AssignAdd[T=DT_FLOAT, _class=["loc:@metrics/accuracy_per_channel/accuracy/total"], use_locking=false, _device="/job:localhost/replica:0/task:0/gpu:0"](metrics/accuracy_per_channel/accuracy/total, metrics/accuracy_per_channel/accuracy/Sum)]]
[[Node: metrics/accuracy_per_channel/Mean/_43 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_858_metrics/accuracy_per_channel/Mean", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
我尝试在交互式调试器中使用tf.get_variable('metrics/accuracy_per_channel/accuracy/total')
,但我得到了:
ValueError: Shape of a new variable (metrics/accuracy_per_channel/accuracy/total) must be fully defined, but instead was <unknown>.
我的理解意味着该变量根本不存在? 任何提示如何进行?