Keras中的math_ops.floor等效项 [英] math_ops.floor equivalent in Keras

查看:144
本文介绍了Keras中的math_ops.floor等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Keras中实现自定义层,需要将浮点[a, 1+a)的张量转换为二进制张量以进行掩膜.我可以看到Tensorflow具有可以执行此操作的floor函数,但是Keras在keras.backend中似乎没有它.知道我该怎么做吗?

I'm trying to implement a custom layer in Keras where I need to convert a tensor of floats [a, 1+a) to a binary tensor for masking. I can see that Tensorflow has a floor function that can do that, but Keras doesn't seem to have it in keras.backend. Any idea how I can do this?

推荐答案

根据OP的要求,我将提及我在评论中给出的答案,并详细说明:

As requested by OP, I will mention the answer I gave in my comment and elaborate more:

简短的回答:如果使用tf.floor(),则不会遇到任何重大问题.

Short answer: you won't encounter any major problems if you use tf.floor().

长答案:在以下情况下,必须使用Keras后端函数(即keras.backend.*):1)需要预处理或扩充传递给实际函数的参数Tensorflow或Theano后端或对返回的结果进行后处理.例如, mean 后端中的方法也可以使用布尔张量作为输入,但是 reduce_mean TF中的方法期望将数值类型作为输入;或2)您想编写一个适用于所有Keras支持的后端的模型.

Long answer: Using Keras backend functions (i.e. keras.backend.*) is necessary in those cases when 1) there is a need to pre-process or augment the argument(s) passed to actual function of Tensorflow or Theano backend or post-process the returned results. For example, the mean method in backend can also work with boolean tensors as input, however the reduce_mean method in TF expects numerical types as input; or 2) you want to write a model that works across all the Keras supported backends.

否则,直接使用大多数真实的后端函数就可以了;但是,如果该功能已在keras.backend模块中定义,则建议改用该功能.

Otherwise, it is fine to use most of real backend functions directly; however, if the function has been defined in keras.backend module, then it is recommended to use that instead.

这篇关于Keras中的math_ops.floor等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆