我正在编写一个基本的神经网络,并希望将其绘制为图片.为此我创建了我需要的所有节点和边缘.
for l, j in zip(self.layers, range(len(self.layers))):
for n, i in zip(l.neurons, range(len(l.neurons))):
fixed_positions[n.identifier] = (j, i)
for l in self.layers:
for n in l.neurons:
for c, w in zip(n.inconnections, n.inconnectionweights):
g.add_edge(n.identifier, c.identifier)
fixed_nodes = fixed_positions.keys()
pos = nx.spring_layout(g, pos=fixed_positions, fixed=fixed_nodes)
Run Code Online (Sandbox Code Playgroud)
蓝点(想象它们在所有边缘)是我想在边缘添加标签的地方,但我不知道该怎么做.它应该适用于任何合理的净大小,即它也适用于resprective层中的4,3和2个神经元.
我正在尝试一些代码,它的行为与我的预期不同。所以我把它简化为一个最低限度的工作示例:
import torch
test_act = torch.tensor([[2.,0.]])
test_target = torch.tensor([0])
loss_function_test = torch.nn.CrossEntropyLoss()
loss_test = loss_function_test(test_act, test_target)
print(loss_test)
> tensor(0.1269)
weights=torch.tensor([0.1,0.5])
loss_function_test = torch.nn.CrossEntropyLoss(weight=weights)
loss_test = loss_function_test(test_act, test_target)
print(loss_test)
> tensor(0.1269)
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,无论是否存在权重,输出都是相同的。但我预计第二个输出是 0.0127
是否有一些我不知道的正常化正在发生?或者它可能被窃听了吗?