question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add LogSoftmax, Softmax, and Dropout modules

See original GitHub issue

I have used a pytorch VGG-16 pre-trained model, added 2 more layers to it to fit my needs and trained the model and saved it as a .pth file. However, when I am trying to convert it to a CrypTen model using the .load() function. It gives the following error

<ipython-input-41-8acf3ddeab54> in <module>()
      1 dummy_model = dummy_model
----> 2 plaintext_model = crypten.load('/content/drive/My Drive/vgg16-model.pth', dummy_model=dummy_model, src=ALICE)
      3 
      4 # Encrypt the model from Alice:
      5 

/usr/local/lib/python3.6/dist-packages/crypten/__init__.py in load(f, encrypted, dummy_model, src, **kwargs)
    233 
    234                 # raise error
--> 235                 raise TypeError("Unrecognized load type %s" % type(result))
    236 
    237         # Non-source party

TypeError: Unrecognized load type <class 'dict'>

I saw in the crypten/__init__.py file that this error is in the block where it is checked whether result which is the return value of torch.load(f, **kwargs), is of type tensor or torch.nn.Module and this error is raised when it is neither of them.

So to check, I ran the result = torch.load(f, **kwargs) command separately and that gave the following error -

AttributeError                            Traceback (most recent call last)

/usr/local/lib/python3.6/dist-packages/torch/serialization.py in _check_seekable(f)
    190     try:
--> 191         f.seek(f.tell())
    192         return True

5 frames

AttributeError: 'VGG' object has no attribute 'seek'


During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)

/usr/local/lib/python3.6/dist-packages/torch/serialization.py in raise_err_msg(patterns, e)
    185                                 " Please pre-load the data into a buffer like io.BytesIO and" +
    186                                 " try to load from it instead.")
--> 187                 raise type(e)(msg)
    188         raise e
    189 

AttributeError: 'VGG' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.

Is there any way to solve this issue so that I can use CrypTen with my pre-trained VGG-16 model?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
noobyogi0010commented, Oct 20, 2019

Hi @lvdmaaten ! I would like to add the Softmax module. Thanks.

0reactions
vshobhacommented, Dec 16, 2019

The Dropout, Softmax and LogSoftmax modules have been added, and their descriptions are available in the documentation. https://crypten.readthedocs.io/

I am closing this issue, feel free to re-open if necessary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python torch.nn.LogSoftmax() Examples - ProgramCreek.com
This page shows Python examples of torch.nn.LogSoftmax.
Read more >
torch.nn — PyTorch 1.13 documentation
A torch.nn.Linear module where in_features is inferred. Dropout Layers. nn.Dropout. During training, randomly zeroes ...
Read more >
tf.keras.layers.Softmax | TensorFlow v2.11.0
Softmax activation function. Inherits From: Layer , Module. View aliases.
Read more >
Guide 3: Debugging in PyTorch - UvA DL Notebooks
Otherwise, PyTorch will apply a log-softmax on your softmax outputs, ... In case your model does not contain dropout, BatchNorm or similar modules, ......
Read more >
Layer activation functions - Keras
Dense(64)) model.add(layers. ... Softmax is often used as the activation for the last layer of a classification ... AlphaDropout (not regular dropout).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found