Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

torch version #7

Open
rom1504 opened this issue Dec 17, 2022 · 4 comments
Open

torch version #7

rom1504 opened this issue Dec 17, 2022 · 4 comments

Comments

@rom1504
Copy link
Contributor

rom1504 commented Dec 17, 2022

class Normalization(nn.Module):
    def __init__(self, shape):
        super().__init__()
        self.register_buffer('mean', torch.zeros(shape))
        self.register_buffer('variance', torch.ones(shape))

    def forward(self, x):
        return (x - self.mean) / self.variance.sqrt()
    

class NSFWModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.norm = Normalization([768])
        self.linear_1 = nn.Linear(768, 64)
        self.linear_2 = nn.Linear(64, 512)
        self.linear_3 = nn.Linear(512, 256)
        self.linear_4 = nn.Linear(256, 1)
        self.act = nn.ReLU()
        self.act_out = nn.Sigmoid()

    def forward(self, x):
        x = self.norm(x)
        x = self.act(self.linear_1(x))
        x = self.act(self.linear_2(x))
        x = self.act(self.linear_3(x))
        x = self.act_out(self.linear_4(x))
        return x

clip_autokeras_binary_nsfw.zip

conversion notebook:
port_nsfw_to_pytorch.zip

from @crowsonkb

@SingL3
Copy link

SingL3 commented Apr 11, 2023

Hi, @rom1504, I tried this and got this error:
ValueError: Unknown optimizer: 'Custom>AdamWeightDecay'. Please ensure you are using a keras.utils.custom_object_scope and that this object is included in the scope. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.

@a574824551
Copy link

Hi, @rom1504, I tried this and got this error: ValueError: Unknown optimizer: 'Custom>AdamWeightDecay'. Please ensure you are using a keras.utils.custom_object_scope and that this object is included in the scope. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.

model = tf.keras.models.load_model(path_to_model, compile=False)

@doublex
Copy link

doublex commented Apr 24, 2023

Is it possible to inference using torch?

@a574824551
Copy link

Is it possible to inference using torch?

yes, I have tried.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants