Tensorboard issue Fastai v2

Hello everyone, I know that might be stupid, but I’m new to Python and Deep learning.

I’m trying to set up tensorboard to monitor my training activities, but I’m getting this kind error:


TypeError Traceback (most recent call last)
in
1 from fastai.callback.tensorboard import *
2 cbs = [TensorBoardCallback(log_dir=‘logs’, projector=True)]
----> 3 learn.fit_one_cycle(3, cbs=cbs)

/opt/conda/lib/python3.7/site-packages/fastai/callback/schedule.py in fit_one_cycle(self, n_epoch, lr_max, div, div_final, pct_start, wd, moms, cbs, reset_opt)
110 scheds = {‘lr’: combined_cos(pct_start, lr_max/div, lr_max, lr_max/div_final),
111 ‘mom’: combined_cos(pct_start, *(self.moms if moms is None else moms))}
–> 112 self.fit(n_epoch, cbs=ParamScheduler(scheds)+L(cbs), reset_opt=reset_opt, wd=wd)
113
114 # Cell

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
209 self.opt.set_hypers(lr=self.lr if lr is None else lr)
210 self.n_epoch = n_epoch
–> 211 self._with_events(self._do_fit, ‘fit’, CancelFitException, self._end_cleanup)
212
213 def _end_cleanup(self): self.dl,self.xb,self.yb,self.pred,self.loss = None,(None,),(None,),None,None

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in with_events(self, f, event_type, ex, final)
158
159 def with_events(self, f, event_type, ex, final=noop):
–> 160 try: self(f’before
{event_type}’); f()
161 except ex: self(f’after_cancel
{event_type}’)
162 self(f’after_{event_type}’); final()

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in call(self, event_name)
139
140 def ordered_cbs(self, event): return [cb for cb in self.cbs.sorted(‘order’) if hasattr(cb, event)]
–> 141 def call(self, event_name): L(event_name).map(self._call_one)
142
143 def _call_one(self, event_name):

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in map(self, f, gen, *args, **kwargs)
152 def range(cls, a, b=None, step=None): return cls(range_of(a, b=b, step=step))
153
–> 154 def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args, gen=gen, **kwargs))
155 def argwhere(self, f, negate=False, **kwargs): return self._new(argwhere(self, f, negate, **kwargs))
156 def filter(self, f=noop, negate=False, gen=False, **kwargs):

/opt/conda/lib/python3.7/site-packages/fastcore/basics.py in map_ex(iterable, f, gen, *args, **kwargs)
664 res = map(g, iterable)
665 if gen: return res
–> 666 return list(res)
667
668 # Cell

/opt/conda/lib/python3.7/site-packages/fastcore/basics.py in call(self, *args, **kwargs)
649 if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
650 fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
–> 651 return self.func(*fargs, **kwargs)
652
653 # Cell

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _call_one(self, event_name)
143 def _call_one(self, event_name):
144 if not hasattr(event, event_name): raise Exception(f’missing {event_name}’)
–> 145 for cb in self.cbs.sorted(‘order’): cb(event_name)
146
147 def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state)

/opt/conda/lib/python3.7/site-packages/fastai/callback/core.py in call(self, event_name)
42 (self.run_valid and not getattr(self, ‘training’, False)))
43 res = None
—> 44 if self.run and _run: res = getattr(self, event_name, noop)()
45 if event_name==‘after_fit’: self.run=True #Reset self.run to True at each end of fit
46 return res

/opt/conda/lib/python3.7/site-packages/fastai/callback/tensorboard.py in before_fit(self)
57 b = self.dls.one_batch()
58 self.learn._split(b)
—> 59 self.writer.add_graph(self.model, *self.xb)
60
61 def after_batch(self):

/opt/conda/lib/python3.7/site-packages/torch/utils/tensorboard/writer.py in add_graph(self, model, input_to_model, verbose)
722 if hasattr(model, ‘forward’):
723 # A valid PyTorch model should have a ‘forward’ method
–> 724 self._get_file_writer().add_graph(graph(model, input_to_model, verbose))
725 else:
726 # Caffe2 models do not have the ‘forward’ method

/opt/conda/lib/python3.7/site-packages/torch/utils/tensorboard/_pytorch_graph.py in graph(model, args, verbose)
284 with torch.onnx.select_model_mode_for_export(model, torch.onnx.TrainingMode.EVAL): # TODO: move outside of torch.onnx?
285 try:
–> 286 trace = torch.jit.trace(model, args)
287 graph = trace.graph
288 torch._C._jit_pass_inline(graph)

/opt/conda/lib/python3.7/site-packages/torch/jit/_trace.py in trace(func, example_inputs, optimize, check_trace, check_inputs, check_tolerance, strict, _force_outplace, _module_class, _compilation_unit)
740 strict,
741 _force_outplace,
–> 742 _module_class,
743 )
744

/opt/conda/lib/python3.7/site-packages/torch/jit/_trace.py in trace_module(mod, inputs, optimize, check_trace, check_inputs, check_tolerance, strict, _force_outplace, _module_class, _compilation_unit)
964 _force_outplace,
965 True,
–> 966 _module_class,
967 )
968 finally:

/opt/conda/lib/python3.7/site-packages/torch/autograd/grad_mode.py in decorate_context(*args, **kwargs)
24 def decorate_context(*args, **kwargs):
25 with self.class():
—> 26 return func(*args, **kwargs)
27 return cast(F, decorate_context)
28

/opt/conda/lib/python3.7/site-packages/torch/jit/_trace.py in _check_trace(check_inputs, func, traced_func, check_tolerance, strict, force_outplace, is_trace_module, _module_class)
325 copied_dict = {}
326 for name, data in inputs.items():
–> 327 copied_dict[name] = _clone_inputs(data)
328 check_mod = torch.jit.trace_module(
329 func.self if hasattr(func, “self”) else func,

/opt/conda/lib/python3.7/site-packages/torch/jit/_trace.py in _clone_inputs(args)
158 return function._nested_map(
159 lambda x: isinstance(x, torch.Tensor), clone_input, condition_msg=“tensors”
–> 160 )(args)
161
162

/opt/conda/lib/python3.7/site-packages/torch/autograd/function.py in _map(obj)
272 def _map(obj):
273 if condition(obj):
–> 274 return fn(obj)
275 elif obj is None:
276 return None

/opt/conda/lib/python3.7/site-packages/torch/jit/trace.py in clone_input(a)
148 a.detach()
149 .clone(memory_format=torch.preserve_format)
–> 150 .requires_grad
(a.requires_grad)
151 )
152 if a.grad is not None:

TypeError: requires_grad_() takes 1 positional argument but 2 were given

I was trying to follow the docs:
https://docs.fast.ai/callback.tensorboard.html

Tenorboard is running on logs/ dir
*from fastai.callback.tensorboard import *
cbs = [TensorBoardCallback(log_dir=‘logs’, projector=True)]
learn.fit_one_cycle(3, cbs=cbs)

Please help me out!

It might work for you, but didn’t work for me
Load with github until the latest release.

pip install git+https://github.com/fastai/fastai
pip install git+https://github.com/fastai/fastcore