softmax with cross entropy 请问到底该怎么用,真的不会啊
Created by: xyq019971
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
trainlist,label=image.gettrainlist('./train/',2)
trainlist,label=image.messuplist(trainlist,label,5)
data=image.data_pro(trainlist,100,100)
#print(data.shape)
#print(label.shape)
a = fluid.layers.data(name='a', shape=[3,100,100],dtype='float32') b = fluid.layers.data(name='b', shape=[1],dtype='float32') out2=fluid.layers.reshape(b,shape=[-1,1]) out5 = fluid.layers.cast(out2, dtype='int64')
conv2d = fluid.layers.conv2d(a,num_filters=10,filter_size=[5, 5],stride=[1, 1],groups=1) d=paddle.fluid.layers.flatten(conv2d , axis=1, name=None) fc1 = fluid.layers.fc(input=d, size=1024, act='relu', name='fc1')
fc2 = fluid.layers.fc(input=fc1, size=2, name='fc2') out = fluid.layers.softmax_with_cross_entropy(logits=fc2, label=out5) '''cost = fluid.layers.cross_entropy(input=fc2, label=label) avg_cost = fluid.layers.mean(x=cost) acc = fluid.layers.accuracy(input=fc2, label=label, k=1)''' test_program = fluid.default_main_program().clone(for_test=True) optimizer = fluid.optimizer.AdamOptimizer(learning_rate=0.001) opt = optimizer.minimize(out) place = fluid.CUDAPlace(0) exe = fluid.Executor(place=place) exe.run(program=fluid.default_startup_program()) for pass_id in range(1): train_cost, train_acc = exe.run(program=fluid.default_main_program(), feed={'a': data, 'b': label}, fetch_list=[fc2,out]) print(train_cost.shape, train_acc)
很简单的猫狗分类了,但是报错啊怎么回事不懂啊 EnforceNotMet: The input of cast op must be set at [/paddle/paddle/fluid/operators/cast_op.cc:42] PaddlePaddle Call Stacks: