首页 Paddle框架 帖子详情
softmax交叉熵优化报错,有人知道怎么回事吗
收藏
快速回复
Paddle框架 问答深度学习模型训练 1542 4
softmax交叉熵优化报错,有人知道怎么回事吗
收藏
快速回复
Paddle框架 问答深度学习模型训练 1542 4

 

EnforceNotMet: The input of cast op must be set at [E:\dist\Paddle\paddle\fluid\operators\cast_op.cc:42]
PaddlePaddle Call Stacks:
Windows not support stack backtrace yet.

 

 

0
收藏
回复
全部评论(4)
时间顺序
于祥
#2 回复于2019-02

你好,能发一下你使用的代码吗

0
回复
麦里梭
#3 回复于2019-02

import paddle.fluid as fluid
import paddle
import numpy as np
from PIL import Image
import os
from multiprocessing import cpu_count
import matplotlib.pyplot as plt
import cnn
import image
import cv2
import time
import enet


def create_loss(predict, label, num_classes):
predict = fluid.layers.transpose(predict, perm=[0, 2, 3, 1])
predict = fluid.layers.reshape(predict, shape=[-1, num_classes])
label = fluid.layers.reshape(label, shape=[-1, 1])
label = fluid.layers.cast(label, dtype="int64")
loss = fluid.layers.softmax_with_cross_entropy(predict, label)
#no_grad_set.append(label.name)
return fluid.layers.reduce_mean(loss)

weightpath=None

x = fluid.layers.data(name='x', shape=[3,200,200],dtype='float32')#数据层python to paddle
y = fluid.layers.data(name='y', shape=[1],dtype='int64')

#*****************
#网络结构
#*****************
u=enet.initial(x) #初始化,输出降采样为1/2
z=enet.downsampling(u,64)#64为通道数,降采样1/2
b1=enet.block1(z,64)#64为通道数
b2=enet.block1(b1,64)#64为通道数
b3=enet.block1(b2,64)#64为通道数
b4=enet.block1(b3,64)#64为通道数
b5=enet.downsampling(b4,64)#64为通道数,降采样1/2
b6=enet.block1(b5,128)#128为通道数
b7=enet.block2(b6,128,2,2)#128为通道数,第三个参数是膨胀数,但三个是padding数
b8=enet.block3(b7,128,[5,1],[2,0])#第三个为卷积核尺寸,第四个为padding尺寸
b9=enet.block2(b8,128,4,4)#128为通道数,第三个参数是膨胀数,但三个是padding数
b10=enet.block1(b9,128)#128为通道数
b11=enet.block2(b10,128,8,8)#128为通道数,第三个参数是膨胀数,但三个是padding数
b12=enet.block3(b11,128,[1,5],[0,2])#第三个为卷积核尺寸,第四个为padding尺寸
b13=enet.block2(b12,128,16,16)#128为通道数,第三个参数是膨胀数,但三个是padding数
b14=enet.upsampling(b13,64)#上采样1倍
b15=enet.block1(b14,64)#64为通道数
b16=enet.block1(b15,64)#64为通道数
b17=enet.upsampling(b16,32)#上采样1倍
b18=enet.block1(b17,32)#128为通道数
b19=enet.upsampling(b18,16)#上采样1倍

b20=enet.block1(b19,16)#64为通道数

b21=enet.block4(b20)

#*****************
#损失函数和优化方法
#*****************
'''b22= fluid.layers.transpose(b21, perm=[0, 2, 3, 1])
out1=fluid.layers.reshape(b22,shape=[-1,9])
out2=fluid.layers.reshape(y,shape=[-1,1])
#out3=paddle.fluid.layers.softmax(out1)
#_, out4 = fluid.layers.topk(out3, k=1)
#out5 = fluid.layers.cast(out4, dtype='float32')
out2 = fluid.layers.cast(out2, dtype='int64')

loss=paddle.fluid.layers.softmax_with_cross_entropy(logits=out1, label=out2)'''
avg=create_loss(b21, y, 9)
#loss=paddle.fluid.layers.square_error_cost(out5, out2)
#avg=fluid.layers.reduce_mean(loss)
regularizer = fluid.regularizer.L2Decay(0.0001)
optimizer = paddle.fluid.optimizer.AdamOptimizer(learning_rate=0.01, beta1=0.9, beta2=0.999, epsilon=1e-08, regularization=regularizer)
#optimizer = fluid.optimizer.Momentum(learning_rate=0.1, momentum=0.9, regularization=regularizer)
_, params_grads = optimizer.minimize(avg,no_grad_set=['y'])


place = fluid.CUDAPlace(0)#CUDA
exe = fluid.executor.Executor(place)
# 进行参数初始化
exe.run(fluid.default_startup_program())#第三部分
if weightpath is not None:
fluid.io.load_params(exe, weightpath)
main_program = fluid.default_main_program()

trainimgs=[]
labelimgs=[]
trainimg=cv2.imread('2.jpg')
labelimg=cv2.imread('2.png')
if len(labelimg.shape) == 2:
labelimg = labelimg[:, :, np.newaxis]
combined = np.concatenate((trainimg, labelimg), axis=2)

combined = cv2.resize(combined, (200, 200))

trainimg = combined[:,:, 0:3]
labelimg = combined[:,:, 3:4]


trainimg=trainimg.transpose((2,0,1))
labelimg=labelimg.transpose((2,0,1))
trainimgs.append(trainimg)
labelimgs.append(labelimg[0,:,:])
trainimgs=np.asarray(trainimgs, np.float32)
labelimgs=np.asarray(labelimgs, np.float32)
labelimgs=labelimgs[:, np.newaxis,:,:]


for i in range(10000):
start=time.time()
b,c,d= exe.run(program=main_program,
feed={'x': trainimgs,'y':labelimgs},
fetch_list=[b21,b21,avg]) #第五部分paddle to python
end=time.time()
end=end-start
print("Pass:%d, Cost:%0.5f,time:%f6" % (i, d,end))
if i%500==0:
fluid.io.save_inference_model(dirname='./weight/'+str(i)+'/', feeded_var_names=['x'],
target_vars=[b21], executor=exe,main_program=main_program)
b=np.asarray(b, np.int32)
#c=np.asarray(c, np.float32)
print(b.shape)
print(c.shape)
print(d.shape)

0
回复
d
denghao1991
#4 回复于2019-03

遇到了同样的问题~~在AIstudio上就没问题,自己的win10电脑上就跑不起························

PaddlePaddle Call Stacks: 
Windows not support stack backtrace yet.

0
回复
6
61012345
#5 回复于2020-02

同问 我也出现了这个问题

0
回复
需求/bug反馈?一键提issue告诉我们
发现bug?如果您知道修复办法,欢迎提pr直接参与建设飞桨~
在@后输入用户全名并按空格结束,可艾特全站任一用户