MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / batch_set_value

Function batch_set_value

tensorflow/python/keras/backend.py:3224–3259  ·  view source on GitHub ↗

Sets the values of many tensor variables at once. Arguments: tuples: a list of tuples `(tensor, value)`. `value` should be a Numpy array.

(tuples)

Source from the content-addressed store, hash-verified

3222
3223@keras_export('keras.backend.batch_set_value')
3224def batch_set_value(tuples):
3225 """Sets the values of many tensor variables at once.
3226
3227 Arguments:
3228 tuples: a list of tuples `(tensor, value)`.
3229 `value` should be a Numpy array.
3230 """
3231 if ops.executing_eagerly_outside_functions():
3232 with ops.init_scope():
3233 for x, value in tuples:
3234 x.assign(np.asarray(value, dtype=dtype(x)))
3235 else:
3236 with get_graph().as_default():
3237 if tuples:
3238 assign_ops = []
3239 feed_dict = {}
3240 for x, value in tuples:
3241 value = np.asarray(value, dtype=dtype(x))
3242 tf_dtype = dtypes_module.as_dtype(x.dtype.name.split('_')[0])
3243 if hasattr(x, '_assign_placeholder'):
3244 assign_placeholder = x._assign_placeholder
3245 assign_op = x._assign_op
3246 else:
3247 # In order to support assigning weights to resizable variables in
3248 # Keras, we make a placeholder with the correct number of dimensions
3249 # but with None in each dimension. This way, we can assign weights
3250 # of any size (as long as they have the correct dimensionality).
3251 placeholder_shape = tensor_shape.TensorShape([None] * value.ndim)
3252 assign_placeholder = array_ops.placeholder(
3253 tf_dtype, shape=placeholder_shape)
3254 assign_op = x.assign(assign_placeholder)
3255 x._assign_placeholder = assign_placeholder
3256 x._assign_op = assign_op
3257 assign_ops.append(assign_op)
3258 feed_dict[assign_placeholder] = value
3259 get_session().run(assign_ops, feed_dict=feed_dict)
3260
3261
3262@keras_export('keras.backend.print_tensor')

Callers

nothing calls this directly

Calls 9

get_graphFunction · 0.85
dtypeFunction · 0.70
get_sessionFunction · 0.70
assignMethod · 0.45
as_defaultMethod · 0.45
splitMethod · 0.45
placeholderMethod · 0.45
appendMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected