English 中文(简体)
• 为微额信贷和中线贷款实施本金分类
原标题:Implementing Binary Classification for LSTM and Linear Layer Output

我正在为我的助手开发一个字灯模型。 我的模型结构包括一个微型、小型、小型和中型终端层,处理音频数据,然后是线性地层。 然而,Im正面临线电视界出乎意料的产出,造成混乱。

在将微额信贷额度的产出(星号:4,32,32)通过后,我预计产出将达到(4,32,1)。 然而,实际产出形态为(4、32、1)。

在我的双轨分类任务中,我的目的是区分两个类别:0至0为“不听觉”和1为“觉醒” 我的批量为32个,我预计产出将形成(32,1个),以表示对每个音频最惠国投入的预测。

能否就“线性”的正确配置或实现预期产出形态所需的任何处理步骤(32,1)向某人提供咨询意见? 任何见解或守则实例都会受到高度赞赏。 以下是我的参考示范守则:

class LSTMWakeWord(nn.Module):
    def __init__(self,input_size,hidden_size,num_layers,dropout,bidirectional,num_of_classes, device= cpu ):
        super(LSTMWakeWord, self).__init__()
        self.input_size = input_size
        self.hidden_size = hidden_size
        self.num_layers = num_layers
        self.device = device
        self.bidirectional = bidirectional
        self.directions = 2 if bidirectional else 1

        self.lstm = nn.LSTM(input_size=input_size,
                            hidden_size = hidden_size,
                            num_layers = num_layers,
                            dropout=dropout,
                            bidirectional=bidirectional,
                            batch_first=True)
        self.layernorm = nn.LayerNorm(input_size)

        self.classifier = nn.Linear(hidden_size , num_of_classes)

    def _init_hidden(self,batch_size):
        n, d, hs = self.num_layers, self.directions, self.hidden_size
        return (torch.zeros(n * d, batch_size, hs).to(self.device),
                torch.zeros(n * d, batch_size, hs).to(self.device))

    def forward(self,x):
        # the values with e+xxx are gone. so it normalizes the values
        x = self.layernorm(x)
        # x shape ->  feature(n_mfcc),batch,seq_len(time)
        hidden = self._init_hidden(x.size()[0])
        out, (hn, cn) = self.lstm(x, hidden)
        print("hn "+str(hn.shape))# directions∗num_layers, batch, hidden_size
        #print("out " + str(out.shape))# batch, seq_len, direction(2 or 1)*hidden_size
        out = self.classifier(hn)
        print("out2 " + str(out.shape))

        return out

我非常赞赏关于如何处理双轨分类的“线”成员产出的任何见解或指导。

问题回答

你可以尝试:

hn = hn[-1, :, :]
out = self.classifier(hn)




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签