[英]AttributeError: 'NoneType' object has no attribute 'name' ( related to different tensorflow versions )
While running the jupyter notebook online in google colab, no error is coming out, but while running the code in offline mode, it's giving following error.在 google colab 中在线运行 jupyter notebook 时,没有出现错误,但是在离线模式下运行代码时,出现以下错误。 : :
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-30-04f071b889cd> in <module>
4 start_time = time.time()
5 x, min_val, info = fmin_l_bfgs_b(evaluator.loss, x.flatten(),
----> 6 fprime=evaluator.grads, maxfun=20)
7 print(min_val)
8 end_time = time.time()
~/anaconda3/lib/python3.7/site-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'],
~/anaconda3/lib/python3.7/site-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)
333 # until the completion of the current minimization iteration.
334 # Overwrite f and g:
--> 335 f, g = func_and_grad(x)
336 elif task_str.startswith(b'NEW_X'):
337 # new iteration
~/anaconda3/lib/python3.7/site-packages/scipy/optimize/lbfgsb.py in func_and_grad(x)
283 else:
284 def func_and_grad(x):
--> 285 f = fun(x, *args)
286 g = jac(x, *args)
287 return f, g
~/anaconda3/lib/python3.7/site-packages/scipy/optimize/optimize.py in function_wrapper(*wrapper_args)
324 def function_wrapper(*wrapper_args):
325 ncalls[0] += 1
--> 326 return function(*(wrapper_args + args))
327
328 return ncalls, function_wrapper
<ipython-input-27-551cb8cb7b3f> in loss(self, x)
6 def loss(self, x):
7 assert self.loss_value is None
----> 8 loss_value, grad_values = eval_loss_and_grads(x)
9 self.loss_value = loss_value
10 self.grad_values = grad_values
<ipython-input-26-8de948cd1256> in eval_loss_and_grads(x)
1 def eval_loss_and_grads(x):
2 x = x.reshape((1, height, width, 3))
----> 3 outs = f_outputs([x])
4 loss_value = outs[0]
5 grad_values = outs[1].flatten().astype('float64')
~/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/backend.py in __call__(self, inputs)
3287 feed_symbols != self._feed_symbols or self.fetches != self._fetches or
3288 session != self._session):
-> 3289 self._make_callable(feed_arrays, feed_symbols, symbol_vals, session)
3290
3291 fetched = self._callable_fn(*array_vals,
~/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/backend.py in _make_callable(self, feed_arrays, feed_symbols, symbol_vals, session)
3213 # Handle fetches.
3214 for x in self.outputs + self.fetches:
-> 3215 callable_opts.fetch.append(x.name)
3216 # Handle updates.
3217 callable_opts.target.append(self.updates_op.name)
AttributeError: 'NoneType' object has no attribute 'name'
In offline mode, following versions of tensoflow and keras respectively : 1.14.0, 2.3.0在离线模式下,tensoflow 和 keras 的版本分别为:1.14.0、2.3.0
In google colab, following versions of tensoflow and keras respectively : 1.15.0, 2.2.5在 google colab 中,分别使用以下 tensoflow 和 keras 版本:1.15.0、2.2.5
[ Note : i checked the code, and when i ran it on colab, it was working. [注意:我检查了代码,当我在 colab 上运行它时,它正在工作。 ] ]
The code is :代码是:
import time
for i in range(iterations):
print('Start of iteration', i)
start_time = time.time()
x, min_val, info = fmin_l_bfgs_b(evaluator.loss, x.flatten(),
fprime=evaluator.grads, maxfun=20)
print(min_val)
end_time = time.time()
print('Iteration %d completed in %ds' % (i, end_time - start_time))
尝试再次安装软件包,因为它解决了我的问题,就像我在 anaconda 环境中再次重新安装了一些冲突的软件包一样
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.