Initialize a network: 1. register CPU/GPU device (with multi-GPU support); 2. initialize the network weights Parameters: net (network) -- the network to be initialized init_type (str) -- the name of an initialization method: normal | xavier | kaiming | orthogonal
(net, init_type='normal', init_gain=0.02, gpu_ids=[])
| 99 | |
| 100 | |
| 101 | def init_net(net, init_type='normal', init_gain=0.02, gpu_ids=[]): |
| 102 | """Initialize a network: 1. register CPU/GPU device (with multi-GPU support); 2. initialize the network weights |
| 103 | Parameters: |
| 104 | net (network) -- the network to be initialized |
| 105 | init_type (str) -- the name of an initialization method: normal | xavier | kaiming | orthogonal |
| 106 | gain (float) -- scaling factor for normal, xavier and orthogonal. |
| 107 | gpu_ids (int list) -- which GPUs the network runs on: e.g., 0,1,2 |
| 108 | |
| 109 | Return an initialized network. |
| 110 | """ |
| 111 | if len(gpu_ids) > 0: |
| 112 | assert(torch.cuda.is_available()) |
| 113 | net.to(gpu_ids[0]) |
| 114 | net = torch.nn.DataParallel(net, gpu_ids) # multi-GPUs |
| 115 | init_weights(net, init_type, init_gain=init_gain) |
| 116 | return net |
| 117 | |
| 118 | |
| 119 | def define_G(input_nc, output_nc, ngf, netG, norm='batch', use_dropout=False, init_type='normal', init_gain=0.02, gpu_ids=[]): |
no test coverage detected