In these lines of code you are transforming the tensor back to a numpy array, which would yield this error:
            inputs= np.array(torch.from_numpy(inputs))
            print(type(inputs))
            if use_cuda:
                inputs = inputs.cuda()

remove the np.array call and just use tensors.
PS: Variables are deprecated since PyTorch 0.4, so you can use tensors now.