keras 运行出现 TypeError: softmax() got an unexpected keyword argument 'axis'.

今天在运行一个简单的keras 程序时出现了 TypeError: softmax() got an unexpected keyword argument 'axis'.   

第一个办法:网上一看是keras 版本和tendorflow 版本出现了问题。建议 tensorflow 版本是1.4.0  

pip install tensorflow-gpu==1.4.0

keras 版本使用 2.1.6 以下的版本 解决。

pip install  keras==2.1.5

这样就可以解决了。在其中安装程序时出现了,发生系统错误5  拒绝访问 这个问题,是说没有权限的问题。网上有一些解决办法。大家可以试试。重要的一点是 你python IDE 有没有关了。把python 程序关了。也许这个问题就解决了。

第二个办法:

 return tf.nn.softmax(x, axis=axis) 改为 return tf.nn.softmax(x, axis)

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
抱歉,我的回答中有误。在Pyswarms中使用PSO算法时,不需要将参数空间bounds作为参数传递给目标函数objective_function,而是将其作为PSO优化器的参数传递。因此,您需要将objective_function()函数修改为以下形式: ```python def objective_function(params): nb_filters, kernel_size, nb_stacks, dilations, dropout_rate = params model = create_tcn_model(input_shape=(15,5), output_shape=1, nb_filters=nb_filters, kernel_size=kernel_size, nb_stacks=nb_stacks, dilations=dilations, dropout_rate=dropout_rate) model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.001), loss='mse') history = model.fit(train_x, train_y, batch_size=32, epochs=100, validation_data=(val_x, val_y), verbose=0) return history.history['val_loss'][-1] ``` 然后,您可以使用以下代码来运行PSO算法并搜索最佳参数配置: ```python # 定义PSO优化器并运行PSO算法 optimizer = ps.single.GlobalBestPSO(n_particles=10, dimensions=5, options={'c1': 0.5, 'c2': 0.3, 'w':0.9}) best_cost, best_params = optimizer.optimize(objective_function, iters=50, bounds=bounds) # 输出最佳参数配置 print('最佳参数配置:') print('nb_filters:', best_params[0]) print('kernel_size:', best_params[1]) print('nb_stacks:', best_params[2]) print('dilations:', best_params[3]) print('dropout_rate:', best_params[4]) ``` 这样,PSO算法就可以自动搜索最佳参数配置,而不会报 "TypeError: objective_function() got an unexpected keyword argument 'bounds'" 错误。希望这次回答能够帮到您。如有其他问题,请随时提出。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值