python - 使用 fmin_l_bfgs_b() 函数时出现 TypeError
问题描述
我fmin_l_bfgs_b
在进行神经风格迁移时使用函数并不断获得
TypeError: 'numpy.float32' object is not callable
错误块的详细信息是:
TypeError Traceback (most recent call last)
<ipython-input-10-4699dceebbd9> in <module>()
----> 1 generate_art('/content/nst_images/5.jpg', '/content/nst_images/a.jpg',1, img_height=400)
4 frames
<ipython-input-9-67cbbed20548> in generate_art(content_image_path, style_image_path, iterations, img_height)
38 for i in range(iterations):
39
---> 40 x, min_val, info = fmin_l_bfgs_b(evaluator.loss(x,img_height,img_width,fetch_loss_and_grads),x, fprime=evaluator.grads, maxfun=20)
41 img = x.copy().reshape((img_height, img_width, 3))
42 img = deprocess_image(img)
/usr/local/lib/python3.6/dist-packages/scipy/optimize/lbfgsb.py in fmin_l_bfgs_b(func, x0, fprime, args, approx_grad, bounds, m, factr, pgtol, epsilon, iprint, maxfun, maxiter, disp, callback, maxls)
197
198 res = _minimize_lbfgsb(fun, x0, args=args, jac=jac, bounds=bounds,
--> 199 **opts)
200 d = {'grad': res['jac'],
201 'task': res['message'],
/usr/local/lib/python3.6/dist-packages/scipy/optimize/lbfgsb.py in _minimize_lbfgsb(fun, x0, args, jac, bounds, disp, maxcor, ftol, gtol, eps, maxfun, maxiter, iprint, callback, maxls, **unknown_options)
343 # until the completion of the current minimization iteration.
344 # Overwrite f and g:
--> 345 f, g = func_and_grad(x)
346 elif task_str.startswith(b'NEW_X'):
347 # new iteration
/usr/local/lib/python3.6/dist-packages/scipy/optimize/lbfgsb.py in func_and_grad(x)
293 else:
294 def func_and_grad(x):
--> 295 f = fun(x, *args)
296 g = jac(x, *args)
297 return f, g
/usr/local/lib/python3.6/dist-packages/scipy/optimize/optimize.py in function_wrapper(*wrapper_args)
325 def function_wrapper(*wrapper_args):
326 ncalls[0] += 1
--> 327 return function(*(wrapper_args + args))
328
329 return ncalls, function_wrapper
TypeError: 'numpy.float32' object is not callable
有关如何解决此问题的任何建议?谢谢!
解决方案
这是一个愚蠢的错误。对于 fmin_l_bfgs_b,损失函数的参数必须作为 args = () 单独传递
推荐阅读
- javascript - 计算 SVG 饼图的百分比
- javascript - PayPal 可变价格智能按钮在没有用户输入的情况下无法执行?
- amazon-lex - 组合多个 Amazon Lex 自动程序的选项
- mysql - MySQL Regexp 解决方案的 Multi-Like 查询
- javascript - 如何在井字游戏的偶数/奇数元素之间切换
- javascript - 在vertical align div,Popper中定位字符串s
- python - 如何将参数从一个类传递到它的两个函数内部?
- python-3.x - Pandas:获取字符开头和结尾之间的子字符串
- python - 使用 pdoc3 获取用户格式化输出
- java - 将 SimpleDateFormat 从 ..Z 更改为 ...+00:00