Fit_one_cycle ZeroDivisionError: division by zero

I’m training the CycleGan from fastai Github on Colab.
I got this error while calling fit_one_cycle it if I use slice as max_lr parameter.

 cycle_gan = CycleGAN(3,3, gen_blocks=9)
 learn = Learner(data, cycle_gan, loss_func=CycleGanLoss(cycle_gan),
                 opt_func=partial(optim.Adam, betas=(0.5,0.99)),
                 callback_fns=[CycleGANTrainer] )

learn.fit_one_cycle(2, slice(1e-6,1e-4))

It works If I use it as a single value.
learn.fit_one_cycle(2, 1e-4)

What could be the problem?

I remember this happening to me last week. Not sure but I think it was because model had a single layer group, can you check output of len(learn.get_layer_groups()) ?

1 Like

I tried and here is the output
AttributeError Traceback (most recent call last)

[<ipython-input-52-6789da740752>](https://localhost:8080/#) in <module>() ----> 1 len(learn.get_layer_groups())

AttributeError: 'Learner' object has no attribute 'get_layer_groups'

Tried this aftwerwards, this gives 1
len(learn.layer_groups)
Did you find a solution if it’s a single layer group?

Doing anything with a slice expects multiple groups. Usually this is done for transfer learning. We cannot do this here as you only have one, hence why you get a ‘div by one’ error

My bad, gave you some old fastai code. It should be learn.layer_groups in v1. Well, slicing is for giving different part of the network different learning rates, but with only 1 it doesn’t make sense. You either use a single value or create your own layer groups

1 Like

Thanks for the answers and help. I think I will continue without slicing.