MTL-Bioinformatics-2016 icon indicating copy to clipboard operation
MTL-Bioinformatics-2016 copied to clipboard

AttributeError: 'Predictor' object has no attribute 'model'

Open afergadis opened this issue 7 years ago • 4 comments

Running the baseline.py I get the error in the title. More precisely the log is the following

models/baseline:using ConllEvaluator for NCBI-disease-IOB-train
models/baseline:using ConllEvaluator for NCBI-disease-IOB-test
Epoch 1/20
135701/135701 [==============================] - 8s - loss: 0.1265 - acc: 0.9620       
models/baseline:Ep: 1 8s (start 2018-01-26 13:31:20, end 2018-01-26 13:31:29)
Traceback (most recent call last):
 File "models/baseline.py", line 71, in <module>
   verbose=config.verbosity
 File "/home/aris/py_envs/py2/local/lib/python2.7/site-packages/keras/engine/training.py", line 1196, in fit
   initial_epoch=initial_epoch)
 File "/home/aris/py_envs/py2/local/lib/python2.7/site-packages/keras/engine/training.py", line 867, in _fit_loop
   callbacks.on_epoch_begin(epoch)
 File "/home/aris/py_envs/py2/local/lib/python2.7/site-packages/keras/callbacks.py", line 62, in on_epoch_begin
   callback.on_epoch_begin(epoch, logs)
 File "/home/aris/biotools/MTL-Bioinformatics-2016/models/ltlib/callbacks.py", line 54, in on_epoch_begin
   callback.on_epoch_begin(*args, **kwargs)
 File "/home/aris/biotools/MTL-Bioinformatics-2016/models/ltlib/callbacks.py", line 31, in on_epoch_begin
   self.after_epoch_end(self.epoch)
 File "/home/aris/biotools/MTL-Bioinformatics-2016/models/ltlib/callbacks.py", line 137, in after_epoch_end
   predictions = self.model.predict(self.dataitems.inputs)
AttributeError: 'Predictor' object has no attribute 'model'

Indeed in line 137 of the callbacks.py there is an attempt to use self.model but call Predictor is never assigned a model in the token_evaluator function, line 200.

afergadis avatar Jan 26 '18 11:01 afergadis

same issue here

stelmath avatar Aug 18 '20 17:08 stelmath

I think inside class CallbackChain(Callback), you should change the function _set_model() into:


    def set_model(self, *args, **kwargs):
        for callback in self._callbacks:
            callback.set_model(*args, **kwargs)

this allows the custom callback to access self.model

stelmath avatar Aug 18 '20 19:08 stelmath

Hi @stelmath, thanks for the suggestion. Did that work for you?

GamalC avatar Aug 25 '20 14:08 GamalC

Yes, works fine for me.

stelmath avatar Aug 26 '20 12:08 stelmath