MCPcopy Create free account
hub / github.com/dek924/PerX2CT / Model

Class Model

taming/modules/diffusionmodules/model.py:195–339  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193
194
195class Model(nn.Module):
196 def __init__(self, *, ch, out_ch, ch_mult=(1,2,4,8), num_res_blocks,
197 attn_resolutions, dropout=0.0, resamp_with_conv=True, in_channels,
198 resolution, use_timestep=True):
199 super().__init__()
200 self.ch = ch
201 self.temb_ch = self.ch*4
202 self.num_resolutions = len(ch_mult)
203 self.num_res_blocks = num_res_blocks
204 self.resolution = resolution
205 self.in_channels = in_channels
206
207 self.use_timestep = use_timestep
208 if self.use_timestep:
209 # timestep embedding
210 self.temb = nn.Module()
211 self.temb.dense = nn.ModuleList([
212 torch.nn.Linear(self.ch,
213 self.temb_ch),
214 torch.nn.Linear(self.temb_ch,
215 self.temb_ch),
216 ])
217
218 # downsampling
219 self.conv_in = torch.nn.Conv2d(in_channels,
220 self.ch,
221 kernel_size=3,
222 stride=1,
223 padding=1)
224
225 curr_res = resolution
226 in_ch_mult = (1,)+tuple(ch_mult)
227 self.down = nn.ModuleList()
228 for i_level in range(self.num_resolutions):
229 block = nn.ModuleList()
230 attn = nn.ModuleList()
231 block_in = ch*in_ch_mult[i_level]
232 block_out = ch*ch_mult[i_level]
233 for i_block in range(self.num_res_blocks):
234 block.append(ResnetBlock(in_channels=block_in,
235 out_channels=block_out,
236 temb_channels=self.temb_ch,
237 dropout=dropout))
238 block_in = block_out
239 if curr_res in attn_resolutions:
240 attn.append(AttnBlock(block_in))
241 down = nn.Module()
242 down.block = block
243 down.attn = attn
244 if i_level != self.num_resolutions-1:
245 down.downsample = Downsample(block_in, resamp_with_conv)
246 curr_res = curr_res // 2
247 self.down.append(down)
248
249 # middle
250 self.mid = nn.Module()
251 self.mid.block_1 = ResnetBlock(in_channels=block_in,
252 out_channels=block_in,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected