首页 > 解决方案 > 如何生成不包括 Keras 输入的随机整数,而不将输入转换为 numpy 数组?

问题描述

将输入和标签传递给 Keras 模型后model.train_on_batch,我希望生成一个随机数,其中不包括传递给模型的输入整数,而无需将数字转换为 numpy 数组。这是我正在谈论的一个例子

#defining Keras model 
the_input = Input(shape=(1,))
the_random = #some function that gives a number between 1 and 100 excluding the input
.....#rest of model
.....
.....#rest of Keras setup
#Keras training, passing input and label to the model
model.train_on_batch( 7 , label)

因此,the_random应该是一个随机整数,不包括输入中给出的数字,在本例中为 7。

我知道一种解决方法是使用tf.keras.backend.eval(the_input )获取输入的 numpy 版本,然后使用函数获取随机数,但我不想进行这种转换以加快训练速度。

如果它有所作为,我使用的后端是 Tensorflow

标签: pythontensorflowkeras

解决方案


推荐阅读