PaddlePaddle在使用ml-1m数据集做分类是出现非法指令错误

  • 关键字:非法指令分类

  • 问题描述:通过使用用户的特征和电影的特征得到余弦相似度,然后想做一个分类的任务,结果在训练的是出现非法指令错误。

  • 报错信息:

<ipython-input-8-476df06ac06a> in train(use_cuda, train_program, params_dirname)
     39         event_handler=event_handler,
     40         reader=train_reader,
---> 41         feed_order=feed_order)

/opt/conda/envs/py35-paddle1.0.0/lib/python3.5/site-packages/paddle/fluid/contrib/trainer.py in train(self, num_epochs, event_handler, reader, feed_order)
    403         else:
    404             self._train_by_executor(num_epochs, event_handler, reader,
--> 405                                     feed_order)
    406 
    407     def test(self, reader, feed_order):

/opt/conda/envs/py35-paddle1.0.0/lib/python3.5/site-packages/paddle/fluid/contrib/trainer.py in _train_by_executor(self, num_epochs, event_handler, reader, feed_order)
    481             exe = executor.Executor(self.place)
    482             reader = feeder.decorate_reader(reader, multi_devices=False)
--> 483             self._train_by_any_executor(event_handler, exe, num_epochs, reader)
    484 
    485     def _train_by_any_executor(self, event_handler, exe, num_epochs, reader):

/opt/conda/envs/py35-paddle1.0.0/lib/python3.5/site-packages/paddle/fluid/contrib/trainer.py in _train_by_any_executor(self, event_handler, exe, num_epochs, reader)
    510                                       fetch_list=[
    511                                           var.name
--> 512                                           for var in self.train_func_outputs
    513                                       ])
    514                 else:

/opt/conda/envs/py35-paddle1.0.0/lib/python3.5/site-packages/paddle/fluid/executor.py in run(self, program, feed, fetch_list, feed_var_name, fetch_var_name, scope, return_numpy, use_program_cache)
    468 
    469         self._feed_data(program, feed, feed_var_name, scope)
--> 470         self.executor.run(program.desc, scope, 0, True, True)
    471         outs = self._fetch_data(fetch_list, fetch_var_name, scope)
    472         if return_numpy:

EnforceNotMet: an illegal instruction was encountered at [/paddle/paddle/fluid/platform/device_context.cc:230]
PaddlePaddle Call Stacks: 
  • 问题复现:通过使用交叉熵损失函数fluid.layers.cross_entropy来计划对于ml-1m数据集做分类,设置输入的数据类型设置为int64,在执行训练时,就会出现以上问题,错误如下:
def train_program():
    scale_infer = inference_program()
    label = layers.data(name='score', shape=[1], dtype='int64')
    square_cost = layers.cross_entropy(input=scale_infer, label=label)
    avg_cost = layers.mean(square_cost)
    return [avg_cost, scale_infer]
  • 解决问题:ml-1m数据集的分类范围是1到5,而分类的label必须要从0开始标记。而个性化推荐模型计算的分数可以使用回归的方式处理,所以可以fluid.layers.square_error_cost接口做一个回归预测。正确代码如下:
def train_program():
    scale_infer = inference_program()
    label = layers.data(name='score', shape=[1], dtype='float32')
    square_cost = layers.square_error_cost(input=scale_infer, label=label)
    avg_cost = layers.mean(square_cost)
    return [avg_cost, scale_infer]
  • 问题拓展:平方误差损失(squared error loss)使用预测值和真实值之间误差的平方作为样本损失,是回归问题中最为基本的损失函数。交叉熵(cross entropy) 是分类问题中使用最为广泛的损失函数。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值