@jpeg729 I just tried that solution, and I got this error:
TypeError: __init__() takes exactly 1 argument (2 given)
I don’t think that my two loss modules are being setup properly.
When I add print commands to each module, nothing shows up in the terminal:
i = 1
for layer in list(cnn):


    if isinstance(layer, nn.ReLU):
        print("ReLU")
        name = "relu_" + str(i)
        model.add_module(name, layer)

        if name in content_layers:
            # add content loss:
            print("Content Loss")
            target = model(content_image_caffe).clone()
            content_loss = ContentLoss(target, content_weight)
            model.add_module("content_loss_" + str(i), content_loss)
            content_losses.append(content_loss)

        if name in style_layers:
            # add style loss:
            print("Content Loss")
            target_feature = model(style_image_caffe).clone()
            target_feature_gram = gram(target_feature).cuda()
            style_loss = StyleLoss(target_feature_gram, style_weight)
            model.add_module("style_loss_" + str(i), style_loss)
            style_losses.append(style_loss)

        i += 1
  
return model, style_losses, content_losses

Using print(layer) is giving me an output like this:

ReLU(inplace)

Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))

ReLU(inplace)

torch.nn.legacy doesn’t support nn.Conv2d, so I had to use ReLU.