java实现one-hot_Tensorflow实现将标签变为one-hot形式

将数据标签变为类似MNIST的one-hot编码形式

def one_hot(indices,

depth,

on_value=None,

off_value=None,

axis=None,

dtype=None,

name=None):

"""Returns a one-hot tensor.

The locations represented by indices in `indices` take value

`on_value`,

while all other locations take value `off_value`.

`on_value` and `off_value` must have matching data types. If

`dtype` is also

provided, they must be the same data type as specified by

`dtype`.

If `on_value` is not provided, it will default to the value `1` with

type

`dtype`

If `off_value` is not provided, it will default to the value `0` with

type

`dtype`

If the input `indices` is rank `N`, the output will have rank

`N+1`. The

new axis is created at dimension `axis` (default: the new axis is

appended

at the end).

If `indices` is a scalar the output shape will be a vector of

length `depth`

If `indices` is a vector of length `features`, the output shape will

be:

```

features x depth if axis == -1

depth x features if axis == 0

```

If `indices` is a matrix (batch) with shape `[batch, features]`, the

output

shape will be:

```

batch x features x depth if axis == -1

batch x depth x features if axis == 1

depth x batch x features if axis == 0

```

If `dtype` is not provided, it will attempt to assume the data

type of

`on_value` or `off_value`, if on

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值