aurora95 / Keras-FCN

Keras-tensorflow implementation of Fully Convolutional Networks for Semantic Segmentation(Unfinished)
MIT License
650 stars 268 forks source link

I want to use my windows10 Ipython to run my datasets, but it shows an error : UnboundLocalError: local variable 'lr' referenced before assignment #80

Open KangKeqiang opened 6 years ago

KangKeqiang commented 6 years ago

UnboundLocalError Traceback (most recent call last)

in () 1 train(batch_size, epochs, lr_base, lr_power, weight_decay, classes, model_name, train_file_path, val_file_path, 2 data_dir, label_dir, target_size=target_size, batchnorm_momentum=batchnorm_momentum, resume_training=resume_training, ----> 3 class_weight=class_weight, loss_fn=loss_fn, metrics=metrics, loss_shape=loss_shape, ignore_label=ignore_label, label_cval=label_cval) in train(batch_size, epochs, lr_base, lr_power, weight_decay, classes, model_name, train_file_path, val_file_path, data_dir, label_dir, target_size, batchnorm_momentum, resume_training, class_weight, dataset, loss_fn, metrics, loss_shape, label_suffix, data_suffix, ignore_label, label_cval) 140 # ), 141 # nb_val_samples = 64 --> 142 class_weight=class_weight 143 ) 144 c:\users\kkq\appdata\local\programs\python\python36\lib\site-packages\keras\legacy\interfaces.py in wrapper(*args, **kwargs) 89 warnings.warn('Update your `' + object_name + 90 '` call to the Keras 2 API: ' + signature, stacklevel=2) ---> 91 return func(*args, **kwargs) 92 wrapper._original_function = func 93 return wrapper c:\users\kkq\appdata\local\programs\python\python36\lib\site-packages\keras\engine\training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch) 1413 use_multiprocessing=use_multiprocessing, 1414 shuffle=shuffle, -> 1415 initial_epoch=initial_epoch) 1416 1417 @interfaces.legacy_generator_methods_support c:\users\kkq\appdata\local\programs\python\python36\lib\site-packages\keras\engine\training_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch) 171 for m in model.stateful_metric_functions: 172 m.reset_states() --> 173 callbacks.on_epoch_begin(epoch) 174 steps_done = 0 175 batch_index = 0 c:\users\kkq\appdata\local\programs\python\python36\lib\site-packages\keras\callbacks.py in on_epoch_begin(self, epoch, logs) 61 logs = logs or {} 62 for callback in self.callbacks: ---> 63 callback.on_epoch_begin(epoch, logs) 64 self._delta_t_batch = 0. 65 self._delta_ts_batch_begin = deque([], maxlen=self.queue_length) c:\users\kkq\appdata\local\programs\python\python36\lib\site-packages\keras\callbacks.py in on_epoch_begin(self, epoch, logs) 627 lr = float(K.get_value(self.model.optimizer.lr)) 628 try: # new API --> 629 lr = self.schedule(epoch, lr) 630 except TypeError: # old API for backward compatibility 631 lr = self.schedule(epoch) in lr_scheduler(epoch, mode) 49 lr = 0.1 50 ---> 51 print('lr: %f' % lr) 52 return lr 53 scheduler = LearningRateScheduler(lr_scheduler) UnboundLocalError: local variable 'lr' referenced before assignment
1057520143 commented 5 years ago

I also encounter this problem. Have you solved it?

KangKeqiang commented 5 years ago

Yes, I had changed the code as follow: def lr_scheduler(epoch): lr_base = 0.01 lr_power= 0.9 lr = lr_base * ((1 - float(epoch)/epochs) ** lr_power) print('lr: %f' % lr) return lr

KangKeqiang commented 5 years ago

Hope it can help you!

1057520143 commented 5 years ago

Hope it can help you!

My E-mail is 1057520143@qq.com.I had other problems during VGG16 training. I don't know whether I could ask you.