Fit_one_cycle throws error at `pbar = master_bar(range(epochs))`

(Yeshwanth Reddy) #1

I’m trying to train an OCR model using fastai…

At fit_one_cycle, I get the error.

The error is occurring as the value for on debugging epochs is 0.003 for some reason.
What could be the fix?

Here’s the full traceback

TypeErrorTraceback (most recent call last)
<ipython-input-9-6d42bc5bc151> in <module>
----> 1 learner.fit_one_cycle(3e-2)

/opt/conda/lib/python3.7/site-packages/fastai/ in fit_one_cycle(learn, cyc_len, max_lr, moms, div_factor, pct_start, wd, callbacks, tot_epochs, start_epoch)
     20     callbacks.append(OneCycleScheduler(learn, max_lr, moms=moms, div_factor=div_factor, pct_start=pct_start, tot_epochs=tot_epochs, 
     21                                        start_epoch=start_epoch))
---> 22, max_lr, wd=wd, callbacks=callbacks)
     24 def lr_find(learn:Learner, start_lr:Floats=1e-7, end_lr:Floats=10, num_it:int=100, stop_div:bool=True, wd:float=None):

/opt/conda/lib/python3.7/site-packages/fastai/ in fit(self, epochs, lr, wd, callbacks)
    176         callbacks = [cb(self) for cb in self.callback_fns] + listify(callbacks)
    177         fit(epochs, self.model, self.loss_func, opt=self.opt,, metrics=self.metrics,
--> 178             callbacks=self.callbacks+callbacks)
    180     def create_opt(self, lr:Floats, wd:Floats=0.)->None:

/opt/conda/lib/python3.7/site-packages/fastai/utils/ in wrapper(*args, **kwargs)
     79         try:
---> 80             return func(*args, **kwargs)
     81         except Exception as e:
     82             if ("CUDA out of memory" in str(e) or

/opt/conda/lib/python3.7/site-packages/fastai/ in fit(epochs, model, loss_func, opt, data, callbacks, metrics)
     77         Use a smaller batch size (batch size={data.train_dl.batch_size} for {len(data.train_dl.dataset)} elements)."""
     78     cb_handler = CallbackHandler(callbacks, metrics)
---> 79     pbar = master_bar(range(epochs))
     80     cb_handler.on_train_begin(epochs, pbar=pbar, metrics=metrics)

TypeError: 'float' object cannot be interpreted as an integer


The documentation for fit_one_cycle ( shows that the argument cycle_len must be a whole number (this is what is meant be ‘int’). This is because the cycle must take place over a whole number of epochs (a whole number of passes over the data). However you have passed in 0.03. Numbers with a decimal point are called floats. The error message – “‘float’ object cannot be interpreted as an integer” – just means that you gave the function a float when it was expecting an int. Try again with a whole number and the error will go away.