How to let not to automatically convert Python namedtuple-inherited class to Julia tuple in PyCall? The following documents have the example such situation:
Python Code:
import torch
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
seq = torch.tensor([[1,2,0], [3,0,0], [4,5,6]])
lens = [2, 1, 3]
packed = pack_padded_sequence(seq, lens, batch_first=True, enforce_sorted=False)
packed
seq_unpacked, lens_unpacked = pad_packed_sequence(packed, batch_first=True)
seq_unpacked
lens_unpacked
Julia Code:
using PyCall
torch = pyimport_conda("torch", "pytorch", "pytorch")
pack_padded_sequence = torch.nn.utils.rnn.pack_padded_sequence
pad_packed_sequence = torch.nn.utils.rnn.pad_packed_sequence
seq = torch.tensor([[1,2,0], [3,0,0], [4,5,6]])
lens = [2, 1, 3]
# Here I expect PackedSequence, which is Python namedtuple-inherited class
# but converted to Julia tuple
packed = pack_padded_sequence(seq, lens, batch_first=true, enforce_sorted=false)
# Fails because packed has no attribute
seq_unpacked, lens_unpacked = pad_packed_sequence(packed, batch_first=true)
seq_unpacked
lens_unpacked
It seems that this issue is related, but it’s very old.