为了账号安全,请及时绑定邮箱和手机立即绑定

用自定义激活替换 sigmoid 激活

用自定义激活替换 sigmoid 激活

哆啦的时光机 2021-06-10 18:09:12
我正在尝试用定义为的分段线性函数替换 Keras sigmoid 函数:def custom_activation_4(x):if x < -6:    return 0elif x >= -6 and x < -4:    return (0.0078*x + 0.049)elif x >= -4 and x < 0:    return (0.1205*x + 0.5)elif x >= 0 and x < 4:    return (0.1205*x + 0.5)elif x >= 4 and x < 6:    return (0.0078*x + 0.951)else:    return 1;当我尝试将其运行为:classifier_4.add(Dense(output_dim = 18, init = 'uniform', activation = custom_activation_4, input_dim = 9))编译器抛出一个错误说:Using a `tf.Tensor` as a Python `bool` is not allowed.我对此进行了研究并了解到,我将变量 x 视为一个简单的 python 变量,而它是一个张量。这就是它不能被视为一个简单的布尔变量的原因。我也尝试使用tensorflow cond方法。这里如何处理和使用 x 作为张量?非常感谢您提供的所有帮助。
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 223 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号