Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

When I feed data into my network, this error occurs.
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
I wanted to feed numpy.ndarray data, but
TypeError: conv2d(): argument 'input' (position 1) must be Tensor, not numpy.ndarray
error occurs. so I changed my input_image to
input_image = Variable(torch.from_numpy(input_image).cuda())

input_image.shape is (64, 3, 28, 28) and type is torch.Tensor.

Here is my network

class Network(nn.Module):
    def __init__(self):
        super(Network, self).__init__()
        self.net= nn.Sequential(
            nn.Conv2d(in_channels=3, out_channels=32, kernel_size=5),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2),

            nn.Conv2d(in_channels=32, out_channels=48, kernel_size=5),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2)
        )

    def forward(self, x):
        x = self.net(x)
        x = x.view(-1, 7 * 7 * 48)
        return x

Anyone can help me ?

Your view doesn’t match the size for the input shape of [64, 3, 28, 28].
Change it to: x = x.view(-1, 4 * 4 * 48).

Also, do you get this error running:

model = Network()
x = torch.randn(64, 3, 28, 28)
output = model(x)

@ptrblck
Thanks for for tell me about MISMATCH of size.
Your example works fine but in my code, there is still something wrong.
I think It is problem of cuda().

I want to use GPU so I add cuda() like this

model = Network().cuda()
model = Network().train()
x = torch.randn(64, 3, 28, 28)
output = model(x)

this code give
RuntimeError: Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor for argument #2 'weight'
so I changed to
x = torch.randn(64, 3, 28, 28)
to
x = Variable(torch.randn(64, 3, 28, 28).cuda())

and It occurs
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

What`s wrong !?

Which PyTorch version are you using?
As you are using Variables it seems your version might be < 0.4.0.
If so, could you first update to the latest stable release, if that’s possible?
You can find the install instructions on the website.

Pytorch version is 0.4.1.
Can you check this codes have problem in usages?

input_image = np.vstack([image1, image2])
input_image = 
Variable(torch.from_numpy(input_image).cuda())
output = model(input_image)

Here is my whole structure:
In main.py, I call train fuction train(model, ...)
and In train() take model

model = model.cuda()
model = model.train()
x = Variable(torch.randn(64, 3, 28, 28).cuda())
output = model(x)

In PyTorch >= 0.4.0 you don’t need Variables anymore, so you can safely remove it.
Anyway, your code runs fine:

model = Network()
model.cuda()

image1 = np.random.randn(1, 3, 28, 28).astype(np.float32)
image2 = np.random.randn(1, 3, 28, 28).astype(np.float32)

input_image = np.vstack([image1, image2])
input_image = torch.from_numpy(input_image).cuda()

output = model(input_image)

Do you get an error using my code snippet?

It`s weird…
When I copy&paste that codes in new.py, It perfectly works.

but I can`t apply same codes in my codes. I’ll test more and tell you the results.
Thank you!

Try to check the dtype or shape of input_image.
That could be a possible source of errors, although I cannot explain the SIGABRT.

@ptrblck

main.py

def main():
 train.train()

train.py

 class Network(nn.Module):
    def __init__(self):
        super(Network, self).__init__()
        self.net= nn.Sequential(
            nn.Conv2d(in_channels=3, out_channels=32, kernel_size=5),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2),

            nn.Conv2d(in_channels=32, out_channels=48, kernel_size=5),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2)
        )

    def forward(self, x):
        x = self.net(x)
        x = x.view(-1, 4 * 4 * 48)  # -1, 7 * 7 * 48
        return x
def trainer():
        model = Network().cuda()

        image1 = np.random.randn(1, 3, 28, 28).astype(np.float32)
        image2 = np.random.randn(1, 3, 28, 28).astype(np.float32)

        input_image = np.vstack([image1, image2])
        input_image = torch.from_numpy(input_image).cuda()
        print(input_image.shape, type(input_image))  # torch.Size([2, 3, 28, 28]) <class 'torch.Tensor'>

        output = model(input_image)
        print(output.shape)

Call train.train() in main.py got Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
and just call train() in train.py, It works.
What the heck!?

Are you calling train.train() or train.trainer()?
The first function seems not to be defined in your code snippets.

I tried your methods using a main.py and it works.

Sorry, of course I did train.trainer().
If you can run this codes then… maybe this is my another problem not the codes.

Could you modify your main to:

import train

def main():
    train.trainer()

if __name__=='__main__':
    main()

and run it again?

I found the code that makes error
from tensorflow.examples.tutorials.mnist import input_data

but I don`t know why this makes error.

Could you try to import MNIST using torchvision?

import torchvision.transforms as transforms
import torchvision.datasets as datasets

train_dataset = datasets.MNIST(
    root='./', download=True, train=True, transform=transforms.ToTensor())

Actually, now I’m trying to converting tensorflow codes to pytorch.
I want to use all pytorch. but in Pytorch MNIST, train set and validation set is combined, and I don`t know how can split them exactly same as tensorflow.

As I know, in pytorch number of MNIST train, test set : [60000, 10000]
and in tensorflow, number of train, test, validation set : [55000, 10000, 5000]
so I tried with tensorflow MNIST dataset.

From this line of code it seems the validation data are the first 5000 images of the train set, while the training data is the rest.

You can split the dataset in the same way using SubsetRandomSampler:

train_dataset = datasets.MNIST(root='./', train=True)
valid_dataset = datasets.MNIST(root='./', train=True)
test_dataset = datasets.MNIST(root='./', train=False)

indices = list(range(len(train_dataset)))
validation_size = 5000
train_idx, valid_idx = indices[validation_size:], indices[:validation_size]
train_sampler = SubsetRandomSampler(train_idx)
valid_sampler = SubsetRandomSampler(valid_idx)

train_loader = DataLoader(
    train_dataset,
    batch_size=64,
    sampler=train_sampler,
    num_workers=2
)

valid_loader = DataLoader(
    valid_dataset,
    batch_size=64,
    sampler=train_sampler,
    num_workers=2
)

test_loader = DataLoader(
    test_dataset,
    batch_size=64,
    num_workers=2
)
1 Like