Solved by Matej_Kompanek in post #2 
              
              
                You could try using dynamic_pointer_cast, for example 
void InitWeights()
{
	for (auto& m : modules(false))
	{
		auto conv3dPtr = std::dynamic_pointer_cast<torch::nn::Conv3dImpl>(m);

		if (conv3dPtr != nullptr)
		{
			torch::nn::init::kaiming_normal_(conv3dPtr->weight, 0.0, torch::kFanOut, torch::k…