RuntimeError: Given groups=1, weight of size [32, 6, 7, 7], expected input[1, 3, 720, 1280] to have 6 channels, but got 3 channels instead

Nicolai_NightVision: <p>i modified a script but it seems to give this error</p>
<pre><code class="lang-auto">(voc_videostyle) C:\Users\Gebruiker\Documents\visionsofchaos\fewshot&gt;python C:\\deepdream-test\\Few-Shot-Patch-Based-Training-master\\generate.py --checkpoint data\project2_train\logs_reference_P\model_00003.pth --data_root "data" --dir_input project2_gen\input_filtered --outdir=data\project2_gen\output --device="cuda:0"
device: cuda:0
Batch 0 / 116
Traceback (most recent call last):
  File "C:\deepdream-test\Few-Shot-Patch-Based-Training-master\generate.py", line 54, in &lt;module&gt;
    net_out = generator(net_in)
  File "C:\Users\Gebruiker\AppData\Roaming\Visions of Chaos\Examples\MachineLearning\venv\voc_videostyle\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\deepdream-test\Few-Shot-Patch-Based-Training-master\models.py", line 111, in forward
    output_0 = self.conv0(x)
  File "C:\Users\Gebruiker\AppData\Roaming\Visions of Chaos\Examples\MachineLearning\venv\voc_videostyle\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\Users\Gebruiker\AppData\Roaming\Visions of Chaos\Examples\MachineLearning\venv\voc_videostyle\lib\site-packages\torch\nn\modules\container.py", line 141, in forward
    input = module(input)
  File "C:\Users\Gebruiker\AppData\Roaming\Visions of Chaos\Examples\MachineLearning\venv\voc_videostyle\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\Users\Gebruiker\AppData\Roaming\Visions of Chaos\Examples\MachineLearning\venv\voc_videostyle\lib\site-packages\torch\nn\modules\conv.py", line 447, in forward
    return self._conv_forward(input, self.weight, self.bias)
  File "C:\Users\Gebruiker\AppData\Roaming\Visions of Chaos\Examples\MachineLearning\venv\voc_videostyle\lib\site-packages\torch\nn\modules\conv.py", line 443, in _conv_forward
    return F.conv2d(input, weight, bias, self.stride,
RuntimeError: Given groups=1, weight of size [32, 6, 7, 7], expected input[1, 3, 720, 1280] to have 6 channels, but got 3 channels instead
</code></pre>
<p>this is the code for the .py file, i saw some other people have similar issues but mine is not being fixed by the answers they get.<br>
does anyone know how to fix this or make it modular so i can use a args command for it if it changes with different generations?</p>
<pre><code class="lang-auto">import argparse
import os
from PIL import Image
from custom_transforms import *
import numpy as np
import torch.utils.data
import time
from data import DatasetFullImages



# Main to generate images
if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--checkpoint", help="checkpoint location", required=True)
    parser.add_argument("--data_root", help="data root", required=True)
    parser.add_argument("--dir_input", help="dir input", required=True)
    parser.add_argument("--dir_x1", help="dir extra 1", required=False)
    parser.add_argument("--dir_x2", help="dir extra 2", required=False)
    parser.add_argument("--dir_x3", help="dir extra 3", required=False)
    parser.add_argument("--outdir", help="output directory", required=True)
    parser.add_argument("--device", help="device", required=True)
    args = parser.parse_args()

    generator = (torch.load(args.checkpoint, map_location=lambda storage, loc: storage))
    generator.eval()

    if not os.path.exists(args.outdir):
        os.mkdir(args.outdir)

    device = args.device
    print("device: " + device, flush=True)

    generator = generator.to(device)
    if device.lower() != "cpu":
        generator = generator.type(torch.half)
    transform = build_transform()
    dataset = DatasetFullImages(args.data_root + "/" + args.dir_input, "ignore", "ignore", device,
                      dir_x1=args.data_root + "/" + args.dir_x1 if args.dir_x1 is not None else None,
                      dir_x2=args.data_root + "/" + args.dir_x2 if args.dir_x2 is not None else None,
                      dir_x3=args.data_root + "/" + args.dir_x3 if args.dir_x3 is not None else None,
                      dir_x4=None, dir_x5=None, dir_x6=None, dir_x7=None, dir_x8=None, dir_x9=None)

    imloader = torch.utils.data.DataLoader(dataset, 1, shuffle=False, num_workers=1, drop_last=False)  # num_workers=4

    generate_start_time = time.time()
    with torch.no_grad():
        for i, batch in enumerate(imloader):
            print('Batch %d / %d' % (i, len(imloader)))

            net_in = batch['pre'].to(args.device)
            if device.lower() != "cpu":
                net_in = net_in.type(torch.half)
            net_out = generator(net_in)

            #image_space_in = to_image_space(batch['image'].cpu().data.numpy())

            #image_space = to_image_space(net_out.cpu().data.numpy())
            image_space = ((net_out.clamp(-1, 1) + 1) * 127.5).permute((0, 2, 3, 1))
            image_space = image_space.cpu().data.numpy().astype(np.uint8)

            for k in range(0, len(image_space)):
                im = image_space[k] #image_space[k].transpose(1, 2, 0)
                Image.fromarray(im).save(os.path.join(args.outdir, batch['file_name'][k]))


    print(f"Generating took {(time.time() - generate_start_time)}", flush=True)
</code></pre>
<p>thanks</p>

ptrblck: <p>Based on the error message it seems that <code>conv0</code> expects an input with 6 channels while your current input tensor contains 3 channels.<br>
I guess you might have changed <code>self.conv0</code> to this setup and might have expected to work with 6 channel inputs?</p>