PyTorch深度学习的反向传播神经网络

我无法建立神经网络。我从图像中填充了测试数据。有人可以帮我做到这一点。

import torch
import torch.nn as nn
import torch.optim as optim
from torch.utils.data import Dataset, DataLoader

test_data的前4个是正方形,后4个是星星,后4个是矩形。

test_data = ((0.111, 0.935), (0.155, 0.958), (0.151, 0.960), (0.153, 0.955),
             (0.111, 0.935), (0.155, 0.958), (0.151, 0.960), (0.153, 0.955),
             (0.111, 0.935), (0.155, 0.958), (0.151, 0.960), (0.153, 0.955),
             (0.111, 0.935), (0.155, 0.958), (0.151, 0.960), (0.153, 0.955),
             (0.715, 0.924), (0.758, 0.964), (0.725, 0.935), (0.707, 0.913),
             (0.715, 0.924), (0.758, 0.964), (0.725, 0.935), (0.707, 0.913),
             (0.715, 0.924), (0.758, 0.964), (0.725, 0.935), (0.707, 0.913),
             (0.715, 0.924), (0.758, 0.964), (0.725, 0.935), (0.707, 0.913),
             (0.167, 0.079), (0.215, 0.081), (0.219, 0.075), (0.220, 0.078),
             (0.167, 0.079), (0.215, 0.081), (0.219, 0.075), (0.220, 0.078),
             (0.167, 0.079), (0.215, 0.081), (0.219, 0.075), (0.220, 0.078),
             (0.167, 0.079), (0.215, 0.081), (0.219, 0.075), (0.220, 0.078),)


class MyDataset(Dataset):
  def __init__(self, features, labels):
        self.labels = labels
        self.features = features

  def __len__(self):
        return len(self.features)

  def __getitem__(self, index):
        X = self.features[index]
        y = self.labels[index]

        return X, y

    class FeedforwardNeuralNetModel(torch.nn.Module):
        def __init__(self):
            pass

        # create forward method
def train(dataloader, model):
    model.train()


def validation(model):
    model.eval()


tensor_x = torch.stack([torch.Tensor(i) for i in train_data])
tensor_y = torch.stack([torch.Tensor(i) for i in train_labels])

dataset_train = MyDataset(tensor_x, tensor_y)

dataloader_train = DataLoader(dataset_train, batch_size=4, shuffle=True)

# create model

# train(dataloader_train, model)
# validation(model)

here is the link if you don't understand what i mean.

评论