使用model_optimize_tool转换Paddle模型失败
Created by: Chgtaxihe
复现用的PaddlePaddle模型:
from paddle import fluid
from paddle.fluid import layers
x = fluid.data(name='value', shape=[1], dtype='float32')
arr = layers.create_array('float32')
step = layers.fill_constant(shape=[1], dtype='int64', value=1)
max_step = layers.fill_constant(shape=[1], dtype='int64', value=5)
zero = layers.fill_constant(shape=[1], dtype='int64', value=0)
layers.array_write(x+1.0, step, array=arr)
condition = layers.less_than(step, max_step)
while_op = layers.While(condition)
with while_op.block():
layers.array_write(x+1, step, array=arr)
layers.increment(step)
layers.less_than(step, max_step, cond=condition)
idx = layers.fill_constant([1], dtype='int64', value=4)
result = layers.array_read(arr, idx)
exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_startup_program())
fluid.io.save_inference_model('./model_output',
feeded_var_names=['value'],
target_vars=[result],
executor=exe,
main_program=fluid.default_main_program())
if __name__ == '__main__':
pass
转换命令:
./model_optimize_tool --model_dir=./infer --valid_targets=arm --optimize_out_type=naive_buffer --optimize_out=infer_out
错误提示:
Can't find a Cast kernel for Cast op: Tensor<arm,int64_t,NCHW,0>:fill_constant_0.tmp_0->Tensor<arm,float,NCHW,0>:write_to_array
按照提示,我应该把step
改为 float 类型,但是按照PaddlePaddle的文档,此处的step
应当为 int64 类型。
请问应该如何解决?