TypeError:squeeze()在使用scipy.optimize.minimize时不接受关键字参数

时间:2019-05-29 07:04:12

标签: python numpy scipy minimize

它抱怨:TypeError:squeeze()没有关键字参数

  

/home/ubuntu/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/numpy/core/fromnumeric.py(1246)squeeze()

基本上,最小化器仅在第一轮工作:当我调试时,第一轮中的aps(字典)和f1输出都是有效的。但是,第二轮的APS变为“ {}”。

def F(x, *args):
    positive_iterable = args[0]
    N = args[1]
    aps = DetectionBenchmark.compute_aps_arr_from_positive_iterable_with_power(positive_iterable, x, N)
    f1 = aps['nmsth_0.3-rel'][0.5]['best_f1']['KEY_VALUE']['f1']
    return -f1

def eval_with_power(input_path, M):
    positive_iterable = DetectionBenchmark.iterate_positives_and_gt_nums_from_cache(input_path)
    pkl_ids = os.listdir(input_path)
    N = len(pkl_ids)
    if M < N:
        N = M
    x0 = np.ones(N)
    res = minimize(F, x0, args=(positive_iterable, N), method='powell', options={'xtol': 1e-8, 'disp': True, 'maxiter': 100})
    return res.x

if __name__ == '__main__':
    M = 100
    input_path = '...'
    x_star = eval_with_power(input_path, M)
    print("The optimal powers given by Powell's method with ", N, " images are ", x_star, ", respectively.")
    print("The optimal F score is ", -F(x_star))

我希望该代码在运行时不会抱怨numpy / core / fromnumeric.py ...

0 个答案:

没有答案