"git@developer.sourcefind.cn:OpenDAS/mmdetection3d.git" did not exist on "79a8299cf8a939f69929db1e543443252fbb6629"
Commit ed2e3bc3 authored by Reed Wanderman-Milne's avatar Reed Wanderman-Milne Committed by A. Unique TensorFlower
Browse files

Convert numpy arrays to floats using float constructor, not .item().

I plan on changing Keras to return Python floats instead of Numpy scalars, and this will break if .item() is called. Also, using the float constructor is cleaner, as it clearly communicates that a Python float is desired.

PiperOrigin-RevId: 297192289
parent fe1fa6d6
...@@ -269,7 +269,7 @@ def build_stats(history, callbacks): ...@@ -269,7 +269,7 @@ def build_stats(history, callbacks):
if history and history.history: if history and history.history:
train_hist = history.history train_hist = history.history
# Gets final loss from training. # Gets final loss from training.
stats['loss'] = train_hist['loss'][-1].item() stats['loss'] = float(train_hist['loss'][-1])
if not callbacks: if not callbacks:
return stats return stats
......
...@@ -94,12 +94,12 @@ class EstimatorBenchmark(tf.test.Benchmark): ...@@ -94,12 +94,12 @@ class EstimatorBenchmark(tf.test.Benchmark):
metrics = [] metrics = []
if 'accuracy' in eval_results: if 'accuracy' in eval_results:
metrics.append({'name': 'accuracy_top_1', metrics.append({'name': 'accuracy_top_1',
'value': eval_results['accuracy'].item(), 'value': float(eval_results['accuracy']),
'min_value': top_1_min, 'min_value': top_1_min,
'max_value': top_1_max}) 'max_value': top_1_max})
if 'accuracy_top_5' in eval_results: if 'accuracy_top_5' in eval_results:
metrics.append({'name': 'accuracy_top_5', metrics.append({'name': 'accuracy_top_5',
'value': eval_results['accuracy_top_5'].item()}) 'value': float(eval_results['accuracy_top_5'])})
if examples_per_sec_hook: if examples_per_sec_hook:
exp_per_second_list = examples_per_sec_hook.current_examples_per_sec_list exp_per_second_list = examples_per_sec_hook.current_examples_per_sec_list
......
...@@ -164,18 +164,18 @@ def build_stats(history, eval_output, callbacks): ...@@ -164,18 +164,18 @@ def build_stats(history, eval_output, callbacks):
""" """
stats = {} stats = {}
if eval_output: if eval_output:
stats['accuracy_top_1'] = eval_output[1].item() stats['accuracy_top_1'] = float(eval_output[1])
stats['eval_loss'] = eval_output[0].item() stats['eval_loss'] = float(eval_output[0])
if history and history.history: if history and history.history:
train_hist = history.history train_hist = history.history
# Gets final loss from training. # Gets final loss from training.
stats['loss'] = train_hist['loss'][-1].item() stats['loss'] = float(train_hist['loss'][-1])
# Gets top_1 training accuracy. # Gets top_1 training accuracy.
if 'categorical_accuracy' in train_hist: if 'categorical_accuracy' in train_hist:
stats[TRAIN_TOP_1] = train_hist['categorical_accuracy'][-1].item() stats[TRAIN_TOP_1] = float(train_hist['categorical_accuracy'][-1])
elif 'sparse_categorical_accuracy' in train_hist: elif 'sparse_categorical_accuracy' in train_hist:
stats[TRAIN_TOP_1] = train_hist['sparse_categorical_accuracy'][-1].item() stats[TRAIN_TOP_1] = float(train_hist['sparse_categorical_accuracy'][-1])
if not callbacks: if not callbacks:
return stats return stats
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment