tensorflow - 什么是火炬的 torch.cat 与 tensorflow 等价?
问题描述
def cxcy_to_xy(cxcy):
"""
Convert bounding boxes from center-size coordinates (c_x, c_y, w, h) to boundary coordinates (x_min, y_min, x_max, y_max).
:param cxcy: bounding boxes in center-size coordinates, a tensor of size (n_boxes, 4)
:return: bounding boxes in boundary coordinates, a tensor of size (n_boxes, 4)
"""
return torch.cat([cxcy[:, :2] - (cxcy[:, 2:] / 2), # x_min, y_min
cxcy[:, :2] + (cxcy[:, 2:] / 2)], 1) # x_max, y_max
我想用 tensorflow 2.0 改变这个 torch.cat
解决方案
几个选项取决于您使用的 TF 中的 API:
tf.concat
- 最类似于torch.cat
:tf.concat(values, axis, name='concat')
tf.keras.layers.concatenate
- 如果您使用 Keras 顺序 API:tf.keras.layers.concatenate(values, axis=-1, **kwargs)
tf.keras.layers.Concatenate
- 如果你使用 Keras 函数式 API:x = tf.keras.layers.Concatenate(axis=-1, **kwargs)(values)
如果您使用的是 Keras API,此答案有助于了解所有 Keras 连接函数之间的差异。
推荐阅读
- vega-lite - 我们如何在 react vega 中实际注册自定义格式化程序?
- docker - 使用 Docker Kubernetes 集群获取 URL 并在没有 Minikube Cluster 的情况下访问正在运行的服务
- java - 布尔值的 Android MutableLiveData 初始化
- java - 带图片的 ViewPager 指示器
- node.js - 当我尝试从“sequelize-typescript”导入 Sequelize 时出现 TypeError
- node.js - 当错误与,req,res和next一起传递时,Express js中间件不起作用
- python - 在单独的图形上绘制 matplotlib 直方图图例
- shadow-dom - shadow dom 内文档变量的值
- python - 如何使用类似 pandas 的界面执行数据库内分析?
- delphi - Rtti:在类中调用方法时获取“无效的类类型转换”