qubvel / efficientnet

Implementation of EfficientNet model. Keras and TensorFlow Keras.
https://arxiv.org/abs/1905.11946
Apache License 2.0
2.07k stars 472 forks source link

ValueError: Unknown activation function:swish #62

Closed wenhuihuang1979 closed 5 years ago

wenhuihuang1979 commented 5 years ago

when I try to load the trained model, it give me "ValueError: Unknown activation function:swish", do you know how to solve that? thanks a lot!

wenhuihuang1979 commented 5 years ago

i solve it by importing layers,

shaunster0 commented 5 years ago

@wenhuihuang1979 what do u mean by 'importing layers'? could u please explain a bit more

Aravinda89 commented 4 years ago

@shaunster0 I'm using tensorflow-gpu==2.1.0rc1, keras==2.3.1 pip install -U efficientnet

use this import efficientnet.tfkeras from tensorflow.keras.models import load_model

instead of import efficientnet.keras

MagnetonBora commented 4 years ago

@shaunster0 I'm using tensorflow-gpu==2.1.0rc1, keras==2.3.1 pip install -U efficientnet

use this import efficientnet.tfkeras from tensorflow.keras.models import load_model

instead of import efficientnet.keras

What works for me, but it is definitely something is wrong with the code.

ImperatorMonclu commented 4 years ago

If you don't want to install efficientnet you use this:

from tensorflow.keras.models import load_model
from tensorflow import nn
from tensorflow.keras.backend import shape
from tensorflow.keras.layers import Dropout

class FixedDropout(Dropout):
    def _get_noise_shape(self, inputs):
        if self.noise_shape is None:
            return self.noise_shape
        return tuple([shape(inputs)[i] if sh is None else sh for i, sh in enumerate(self.noise_shape)])

customObjects = {
    'swish': nn.swish,
    'FixedDropout': FixedDropout
}

model = load_model('model.h5', custom_objects=customObjects)
cmehrshad commented 4 years ago

For the record, I had trained my model using efficientnet.keras.EfficientNetB0 and I had the same problem when I reloaded for inference.

I solved it by simply importing efficientnet.keras.

ghost commented 4 years ago

For the record, I had trained my model using efficientnet.keras.EfficientNetB0 and I had the same problem when I reloaded for inference.

I solved it by simply importing efficientnet.keras.

how, can you share your implementation please