fluid layers.reshape如何输入shape
构建的部分网络结构如下,其中input是一个3d的tensor,shape为(batch_size, num_vector, vector_dim),想将input reshape到二维,不知道shape怎么给比较合适,按现在的代码会报错。
def nw_2dvector_to_1dvector(input, vector_dim): shape = fluid.layers.shape(input) batch_size, num_vectors = shape[0], shape[1] reshaped = fluid.layers.reshape(input, shape=[batch_size * num_vectors, vector_dim]) fc = fluid.layers.fc(input=reshaped, size=HIDDEN1, act='relu') reshaped2 = fluid.layers.reshape(fc, shape=[batch_size, num_vectors, HIDDEN1]) reduced = fluid.layers.reduce_mean(reshaped2, dim=0) fc2 = fluid.layers.fc(input=reduced, size=HIDDEN1, act='relu') return fc2
错误信息:
Traceback (most recent call last):
File "onehot_train_paddle_lod.py", line 342, in
- 版本、环境信息: 1)PaddlePaddle版本:1.3.2-gpu 3)GPU:Tesla P40, CUDA9.0 4)系统环境:CentOS,Python版本3.5.2
shape = fluid.layers.shape(input) 改成 shape = input.shape 试下
shape = fluid.layers.shape(input) 改成 shape = input.shape 试下
试了一下,前面这个问题确实没有了,但是后面第二个reshape的地方还是报错
Traceback (most recent call last):
File "onehot_train_paddle_lod.py", line 343, in
这个报错说明input.shape里读取的batch_size和num_vectors都是-1, 应该是传入的input之前做过第二的reshape操作之类的,把batch_size和num_vectors其中有一个指定为具体值就可以了
这个报错说明input.shape里读取的batch_size和num_vectors都是-1, 应该是传入的input之前做过第二的reshape操作之类的,把batch_size和num_vectors其中有一个指定为具体值就可以了
Batch size理论上是可以指定的,但是不太清楚怎么处理最后一个batch大小不等于batch size的情况
这个报错说明input.shape里读取的batch_size和num_vectors都是-1, 应该是传入的input之前做过第二的reshape操作之类的,把batch_size和num_vectors其中有一个指定为具体值就可以了
Batch size理论上是可以指定的,但是不太清楚怎么处理最后一个batch大小不等于batch size的情况
一般选择drop_last或者padding的方式
这个报错说明input.shape里读取的batch_size和num_vectors都是-1, 应该是传入的input之前做过第二的reshape操作之类的,把batch_size和num_vectors其中有一个指定为具体值就可以了
Batch size理论上是可以指定的,但是不太清楚怎么处理最后一个batch大小不等于batch size的情况
一般选择drop_last或者padding的方式
请问两个选项在哪里指定?
https://github.com/PaddlePaddle/Paddle/blob/24923f760497e6b0ae9abbc96382e55fa218ffa9/python/paddle/batch.py#L18
这个报错说明input.shape里读取的batch_size和num_vectors都是-1, 应该是传入的input之前做过第二的reshape操作之类的,把batch_size和num_vectors其中有一个指定为具体值就可以了
Batch size理论上是可以指定的,但是不太清楚怎么处理最后一个batch大小不等于batch size的情况
一般选择drop_last或者padding的方式
请问两个选项在哪里指定?
https://github.com/PaddlePaddle/Paddle/blob/24923f760497e6b0ae9abbc96382e55fa218ffa9/python/paddle/batch.py#L18
reshaped2 = fluid.layers.reshape(fc, shape=[BATCH_SIZE, -1, HIDDEN1]) 固定batch_size后reshape报一下错误
Traceback (most recent call last):
File "onehot_train_paddle_lod.py", line 345, in
另外想请教一下如何在运行时动态的获取Tensor实际的shape?(不是定义网络结构的时候给的shape)
另外想请教一下如何在运行时动态的获取Tensor实际的shape?(不是定义网络结构的时候给的shape)
fluid.layers.shape