python - 如何生成不包括 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
解决方案
推荐阅读
- javascript - 使用 p 标签将 textarea 值转换为 html 内容
- python - 使用python将NULL插入到sql中的float数据类型列
- cypress - 赛普拉斯不重试断言
- php - Php mailer 电子邮件消息被阻止
- asp.net-mvc - 带有表单发布的核心 MVC 多次提交按钮未按预期路由
- angular - 根据值创建数组 - Angular 2
- r - 用自然二次样条对纵向数据建模的最小时间点?
- elasticsearch - 需要针对以下所需场景的弹性搜索查询
- linux - 无法连接到 PDB、Oracle 19C Linux RH7.7 ORA-01034、ORA-27101
- angular - 在 ng2 图表中使用函数