PyTorch: How to write a neural network that only returns the weights?

Rani

I'm training a neural network that learns some weights and based on those weights, I compute transformations that produce the predicted model in combination with the weights. My network doesn't learn properly and therefore I'm writing a different network that does nothing but returning the weights independent from the input x (after normalization with softmax and transpose). This way, I want to find out whether the problem lies in the network or in the transformation estimation outside the network. But this doesn't work. This is what I've got.

class DoNothingNet(torch.nn.Module):
    def __init__(self, n_vertices=6890, n_joints=14):
        super(DoNothingNet, self).__init__()
        self.weights = nn.parameter.Parameter(torch.randn(n_vertices, n_joints))

    def forward(self, x, indices):
        self.weights = F.softmax(self.weights, dim=1)
        return self.weights.transpose(0,1)

But the line self.weights = F.softmax(self.weights, dim=1) doesn't work and produces the error TypeError: cannot assign 'torch.cuda.FloatTensor' as parameter 'weights' (torch.nn.Parameter or None expected). How do I fix this? And does the code even make sense?

antoleb

nn.Module tracks all fields of type nn.Parameter for training. In your code every forward call you try to change parameters weights by assigning it to Tensor type, so the error occurs.

The following code outputs normalised weights without changing the stored ones. Hope this will help.

import torch
from torch import nn
from torch.nn import functional as F

class DoNothingNet(torch.nn.Module):
    def __init__(self, n_vertices=6890, n_joints=14):
        super(DoNothingNet, self).__init__()
        self.weights = nn.parameter.Parameter(torch.randn(n_vertices, n_joints))

    def forward(self, x, indices):
        output = F.softmax(self.weights, dim=1)
        return output.transpose(0,1)

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Weights in Neural Network

分類Dev

Accessing neural network weights and neuron activations

分類Dev

How to apply a trained neural network to write outputs into a csv file?

分類Dev

Weights given by MLPClassifier in sklearn.neural_network (Python)

分類Dev

Any pytorch tools to monitor neural network's training?

分類Dev

How to store neural network knowledge data?

分類Dev

My neural network can only predict one class

分類Dev

Cordova network isOnline returns true only on WiFi

分類Dev

How can I load the weights of some layer of a trained network in a new network in returnn?

分類Dev

How to interpret the file mean.binaryproto when loading a Neural Network?

分類Dev

How add dropout into my tensorflow neural network with RNNCells?

分類Dev

How do I implement multilabel classification neural network with keras

分類Dev

How is the range of the last layer of a Neural Network determined when using ReLU

分類Dev

How to incorporate user feedback into a multi-choice Convolutional Neural Network?

分類Dev

For binary classification using neural network how many output units to be used

分類Dev

Use of loss functions in updating weights of neural networks

分類Dev

Confusion with weights dumping from neural net in keras

分類Dev

Neural Network: Solving XOR

分類Dev

FizzBuzz Neural Network

分類Dev

Retrain of a neural network

分類Dev

Inconsistent Neural Network output

分類Dev

Neural network for optimization problems

分類Dev

Stabilizing Neural Network

分類Dev

What if we do not apply activation to the hidden layers and only to the output layer of a feed forward neural network?

分類Dev

How to write to a file over network sharing center

分類Dev

Different methods for initializing embedding layer weights in Pytorch

分類Dev

Pytorch autograd.grad how to write the parameters for multiple outputs?

分類Dev

Trouble understanding Convolutional Neural Network

分類Dev

Issue in bootstrapping a neural network in r

Related 関連記事

  1. 1

    Weights in Neural Network

  2. 2

    Accessing neural network weights and neuron activations

  3. 3

    How to apply a trained neural network to write outputs into a csv file?

  4. 4

    Weights given by MLPClassifier in sklearn.neural_network (Python)

  5. 5

    Any pytorch tools to monitor neural network's training?

  6. 6

    How to store neural network knowledge data?

  7. 7

    My neural network can only predict one class

  8. 8

    Cordova network isOnline returns true only on WiFi

  9. 9

    How can I load the weights of some layer of a trained network in a new network in returnn?

  10. 10

    How to interpret the file mean.binaryproto when loading a Neural Network?

  11. 11

    How add dropout into my tensorflow neural network with RNNCells?

  12. 12

    How do I implement multilabel classification neural network with keras

  13. 13

    How is the range of the last layer of a Neural Network determined when using ReLU

  14. 14

    How to incorporate user feedback into a multi-choice Convolutional Neural Network?

  15. 15

    For binary classification using neural network how many output units to be used

  16. 16

    Use of loss functions in updating weights of neural networks

  17. 17

    Confusion with weights dumping from neural net in keras

  18. 18

    Neural Network: Solving XOR

  19. 19

    FizzBuzz Neural Network

  20. 20

    Retrain of a neural network

  21. 21

    Inconsistent Neural Network output

  22. 22

    Neural network for optimization problems

  23. 23

    Stabilizing Neural Network

  24. 24

    What if we do not apply activation to the hidden layers and only to the output layer of a feed forward neural network?

  25. 25

    How to write to a file over network sharing center

  26. 26

    Different methods for initializing embedding layer weights in Pytorch

  27. 27

    Pytorch autograd.grad how to write the parameters for multiple outputs?

  28. 28

    Trouble understanding Convolutional Neural Network

  29. 29

    Issue in bootstrapping a neural network in r

ホットタグ

アーカイブ