cambridgeltl / MTL-Bioinformatics-2016

Creative Commons Attribution 4.0 International
217 stars 92 forks source link

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

Open afergadis opened 6 years ago

afergadis commented 6 years ago

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.

stelmath commented 4 years ago

same issue here

stelmath commented 4 years ago

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

GamalC commented 4 years ago

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

stelmath commented 4 years ago

Yes, works fine for me.