From ebeb598c2d1f341d6d641bf58c370cf7b43f6e37 Mon Sep 17 00:00:00 2001 From: "Joshua V. Dillon" Date: Fri, 1 Mar 2019 17:24:16 -0800 Subject: [PATCH] Correctly check shape not None in Keras `add_weight`. When calling Keras add_weight with a np list, as written the `shape or ()` "trick" results in the following exception: """ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()""" This change fixes the problem by using an explicit `if`. PiperOrigin-RevId: 236407103 --- tensorflow/python/keras/engine/base_layer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tensorflow/python/keras/engine/base_layer.py b/tensorflow/python/keras/engine/base_layer.py index c516d5dd433..6ecf39547f5 100644 --- a/tensorflow/python/keras/engine/base_layer.py +++ b/tensorflow/python/keras/engine/base_layer.py @@ -310,7 +310,8 @@ class Layer(trackable.Trackable): ValueError: When giving unsupported dtype and no initializer or when trainable has been set to True with synchronization set as `ON_READ`. """ - shape = shape or () + if shape is None: + shape = () # Validate optional keyword arguments. for kwarg in kwargs: if kwarg not in ['getter', 'collections', 'experimental_autocast']: