"tests/vscode:/vscode.git/clone" did not exist on "a9c83bce15246c3e71e372e8128c7e345c136f36"
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):
if history and history.history:
train_hist = history.history
# Gets final loss from training.
stats['loss'] = train_hist['loss'][-1].item()
stats['loss'] = float(train_hist['loss'][-1])
if not callbacks:
return stats
......
......@@ -94,12 +94,12 @@ class EstimatorBenchmark(tf.test.Benchmark):
metrics = []
if 'accuracy' in eval_results:
metrics.append({'name': 'accuracy_top_1',
'value': eval_results['accuracy'].item(),
'value': float(eval_results['accuracy']),
'min_value': top_1_min,
'max_value': top_1_max})
if 'accuracy_top_5' in eval_results:
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:
exp_per_second_list = examples_per_sec_hook.current_examples_per_sec_list
......
......@@ -164,18 +164,18 @@ def build_stats(history, eval_output, callbacks):
"""
stats = {}
if eval_output:
stats['accuracy_top_1'] = eval_output[1].item()
stats['eval_loss'] = eval_output[0].item()
stats['accuracy_top_1'] = float(eval_output[1])
stats['eval_loss'] = float(eval_output[0])
if history and history.history:
train_hist = history.history
# Gets final loss from training.
stats['loss'] = train_hist['loss'][-1].item()
stats['loss'] = float(train_hist['loss'][-1])
# Gets top_1 training accuracy.
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:
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:
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