Hi, I am using a github repo, so I am not sure if I can post there code. Can I? This is a segmentation problem. The network is called ConvPoint.
Here is the executable code from my notebook:
from networks.network_seg import SegBig as Net
model = Net(1,10) # input channels and number of classess
PATH = './state00_dict.pth'
model.load_state_dict(torch.load(PATH, map_location = device))
model = nn.Sequential(*list(model.children())[:-22])
for param in model.parameters():
param.requires_grad = False
class Flatten(nn.Module):
def __init__(self):
super(Flatten, self).__init__()
def forward(self,x):
x = x.view(x.size(0),-1)
return x
model_new = nn.Sequential(model, PtConv(64, 64, 16, 3, use_bias=False), Flatten(), nn.Linear(64+64, 10), nn.ReLU(), nn.Dropout(0.4))
train_dir = os.path.join('./training_10')
filelist_train = [dataset for dataset in os.listdir(train_dir)]
print(f"done, {len(filelist_train)} train file")
import npm3d_seg as npm
ds = npm.PartDataset(filelist_train, train_dir,
training=True, block_size=8,
iteration_number=8*1000,
npoints=8192)
train_loader = torch.utils.data.DataLoader(ds, batch_size=8, shuffle=True,
num_workers=4
)
optimizer = torch.optim.Adam(model_new.parameters(), lr=1e-3)
for epoch in range(1000):
model_new.train()
train_loss = 0
N_CLASSES = 10
cm = np.zeros((N_CLASSES, N_CLASSES))
t = tqdm(train_loader, ncols=100, desc="Epoch {}".format(epoch))
for pts, features, seg in t:
features = features.to(device)
pts = pts.to(device)
seg = seg.to(device)
optimizer.zero_grad()
outputs = model_new(features, pts)
loss = F.cross_entropy(outputs.view(-1, N_CLASSES), seg.view(-1))
loss.backward()
optimizer.step()
The error is:
TypeError Traceback (most recent call last)
<ipython-input-36-24e2b7e6760e> in <module>
10 seg = seg.to(device)
11 optimizer.zero_grad()
---> 12 outputs = model_new(features, pts)
13
14 loss = F.cross_entropy(outputs.view(-1, N_CLASSES), seg.view(-1))
~/anaconda3/envs/pytorch/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
539 result = self._slow_forward(*input, **kwargs)
540 else:
--> 541 result = self.forward(*input, **kwargs)
542 for hook in self._forward_hooks.values():
543 hook_result = hook(self, input, result)
TypeError: forward() takes 2 positional arguments but 3 were given