I am trying to put together a metric for coarse segmentation with on tensorflow for using with keras:
https://gist.github.com/DSLituiev/1adcc94b7e4e2b1861d39bbbc2db7307
I read this issue, which suggests one must use local variable initializer, which I did, but I am still getting the exception:
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"]()]]
I tried to use tf.get_variable('metrics/accuracy_per_channel/accuracy/total')
in an interactive debugger, but I am getting:
ValueError: Shape of a new variable (metrics/accuracy_per_channel/accuracy/total) must be fully defined, but instead was <unknown>.
Which to my understanding implies that the variable does not exist at all? Any tips how to proceed?