小编New*_*irl的帖子

Pytorch 张量,如何切换通道位置 - 运行时错误

我的训练数据集如下,其中 X_train 是具有 3 个通道的 3D

X_Train 的形状:(708, 256, 3) Y_Train 的形状:(708, 4)

然后我将它们转换为张量并输入到数据加载器中:

X_train=torch.from_numpy(X_data)
y_train=torch.from_numpy(y_data)
training_dataset = torch.utils.data.TensorDataset(X_train, y_train)
train_loader = torch.utils.data.DataLoader(training_dataset, batch_size=50, shuffle=False)
Run Code Online (Sandbox Code Playgroud)

但是,在训练模型时,我收到以下错误:RuntimeError: Given groups=1, weight of size 24 3 5, expected input[708, 256, 3] to have 3 channels, but got 256 channels代替

我想这是由于频道的位置?在 Tensorflow 中,通道位置在末尾,但在 PyTorch 中,格式是“批量大小 x 通道 x 高度 x 宽度”?那么如何交换 x_train 张量中的位置以匹配数据加载器中的预期格式?

class TwoLayerNet(torch.nn.Module):
    def __init__(self):
        super(TwoLayerNet,self).__init__()
        self.conv1 = nn.Sequential(
            nn.Conv1d(3, 3*8, kernel_size=5, stride=1),  
            nn.Sigmoid(),
            nn.AvgPool1d(kernel_size=2, stride=0))
        self.conv2 = nn.Sequential(
            nn.Conv1d(3*8, 12, kernel_size=5, …
Run Code Online (Sandbox Code Playgroud)

python-3.x conv-neural-network pytorch

12
推荐指数
1
解决办法
9900
查看次数

如何将自定义数据放入 Pytorch DataLoader 中?

我已经对数据进行了预处理和标准化,并分为训练集和测试集。我的 x_train 和 y_train 有以下尺寸: X_Train 的形状:(708, 256, 3) Y_Train 的形状:(708, 4)

如您所见,x_train 是 3-D 的。我怎样才能将它输入到 pytorch 数据加载器中?我应该在班级块中放置什么?

class training_set(Dataset):
    def __init__(self,X,Y):

    def __len__(self):
        return 

    def __getitem__(self, idx):
        return 

training_set = torch.utils.data.TensorDataset(x_train, y_train)
train_loader = torch.utils.data.DataLoader(training_set, batch_size=50, shuffle=True)
Run Code Online (Sandbox Code Playgroud)

neural-network python-3.x conv-neural-network pytorch

4
推荐指数
1
解决办法
2453
查看次数

熊猫情节线具有不同的线条样式?

我正在使用该ggplot样式在同一个图上绘制多条线。采用这种风格,线条就变成了全实线。所以能见度不好。如何将每条线更改为不同的样式,例如带有虚线的样式或其他样式?

import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('ggplot')

fig,ax = plt.subplots(figsize=(15,5))
ax.set_title('Loss curve', fontsize=15)
ax.set_ylabel('Loss')
ax.set_xlabel('Epoch')
df1.plot.line(ax=ax,x='epoch',y=["train_loss"])
df2.plot.line(ax=ax,x='epoch',y=["train_loss"])
plt.show()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

python matplotlib pandas

3
推荐指数
1
解决办法
7931
查看次数