kchengiva / Shift-GCN

The implementation for "Skeleton-Based Action Recognition with Shift Graph Convolutional Network" (CVPR2020 oral).
Other
269 stars 55 forks source link

RuntimeError: input.is_contiguous() #28

Open WurmD opened 3 years ago

WurmD commented 3 years ago

Hi, did this ever happen to you?

RuntimeError: input.is_contiguous() INTERNAL ASSERT FAILED at "shift_cuda.cpp":21, please report a bug to PyTorch. input must be contiguous

Full trace:

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/mnt/home/dario/.vscode-server/extensions/ms-python.python-2021.3.658691958/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
    cli.main()
  File "/mnt/home/dario/.vscode-server/extensions/ms-python.python-2021.3.658691958/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 444, in main
    run()
  File "/mnt/home/dario/.vscode-server/extensions/ms-python.python-2021.3.658691958/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 285, in run_file
    runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
  File "/usr/lib/python3.6/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/usr/lib/python3.6/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/mnt/home/dario/Shift-GCN/load_shiftgcn_model.py", line 45, in <module>
    output = model(fp)
  File "/home/dario/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/mnt/home/dario/Shift-GCN/model/shift_gcn.py", line 200, in forward
    x = self.l1(x)
  File "/home/dario/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/mnt/home/dario/Shift-GCN/model/shift_gcn.py", line 161, in forward
    x = self.tcn1(self.gcn1(x)) + self.residual(x)
  File "/home/dario/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/mnt/home/dario/Shift-GCN/model/shift_gcn.py", line 68, in forward
    x = self.shift_in(x)
  File "/home/dario/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "./model/Temporal_shift/cuda/shift.py", line 45, in forward
    return ShiftFunction.apply(input,self.xpos,self.ypos,self.stride)
  File "./model/Temporal_shift/cuda/shift.py", line 19, in forward
    output = shift_cuda.forward(input,xpos,ypos,stride)
RuntimeError: input.is_contiguous() INTERNAL ASSERT FAILED at "shift_cuda.cpp":21, please report a bug to PyTorch. input must be contiguous

Input fp:

tensor([[[[[-0.0102,  0.0000],
           ...,
           ...,
           [ 0.3775,  0.0000]]]]], device='cuda:0')
requires_grad:False
shape:torch.Size([1, 3, 300, 25, 2])

Minimal exemple:

from collections import OrderedDict
import numpy as np
import os
import sys
import torch
from torch.autograd import Variable

sys.path.append("./data_gen/") # so ntu_gendata can import preprocess
from data_gen.ntu_gendata import pre_normalization, read_xyz
from model.shift_gcn import Model

device = 'cuda'

model_args = {'graph': 'graph.ntu_rgb_d.Graph', 'graph_args': {'labeling_mode': 'spatial'}, 'num_class': 60, 'num_person': 2, 'num_point': 25}
model = Model(**model_args).to(device)
model.eval()

weights = torch.load('/home/dario/temp/synse_resources/ntu_results/shift_5_r/weights/best.pt')
weights = OrderedDict(
    [[k.split('module.')[-1],
        v.to(device)] for k, v in weights.items()])
model.load_state_dict(weights)

MAX_BODY_KINECT = 4

NUM_SAMPLES = 1
NUM_JOINT = 25
MAX_FRAME = 300
MAX_BODY_TRUE = 2
fp = np.zeros((NUM_SAMPLES, 3, MAX_FRAME, NUM_JOINT, MAX_BODY_TRUE), dtype=np.float32)

sample = '/home/dario/temp/datasets/NTU-60_and-120/skeletons/S001C001P001R001A001.skeleton'
data = read_xyz(sample, max_body=MAX_BODY_KINECT, num_joint=NUM_JOINT)
fp[0, :, 0:data.shape[1], :, :] = data
# print(fp)
fp = pre_normalization(fp)
fp = torch.from_numpy(fp)
fp = Variable(fp.float().to(device), requires_grad=False) # , volatile=True)
output = model(fp)
_, predict_label = torch.max(output.data, 1)
print(sample,':',predict_label)
Droppledev commented 3 years ago

I had the same problem but I found the solution

The error happened in the ./model/Temporal_shift/cuda/shift.py and from the error, we know that the input must be contiguous The simple solution is to convert the input to be contiguous first with: input = input.contiguous() before this line output = shift_cuda.forward(input,xpos,ypos,stride)

Here is the reference

Hope it helps 😄

WurmD commented 3 years ago

Indeed it works! Thanks! I'll leave the Issue open until that fix is implemented in the repo

ikuta23 commented 2 months ago

I had the same problem but I found the solution

The error happened in the ./model/Temporal_shift/cuda/shift.py and from the error, we know that the input must be contiguous The simple solution is to convert the input to be contiguous first with: input = input.contiguous() before this line output = shift_cuda.forward(input,xpos,ypos,stride)

Here is the reference

Hope it helps 😄

You're a genius! Thanks so much!