I hereby claim:
- I am cflamant on github.
- I am cflamant (https://keybase.io/cflamant) on keybase.
- I have a public key ASB9Tyc25osLdZyP8GTH4CdMt8Qz4kF3xJQCqH3sDfkwkwo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
""" | |
Code to demonstrate dynamically creating subclasses for a | |
superclass that is not known before execution. | |
General idea: you want to make a subclass that is a baby animal, | |
but you don't know whether it will be a Human or Sheep (or possibly | |
another animal from a different module) until the code is run. | |
By creating the subclass dynamically (using the "type" function), | |
you can avoid writing a separate subclass for each superclass possibility. |
## Example training loop from within a class which contains | |
## a PyTorch nn.Module() under the variable self.net() | |
optimizer = optim.SGD(self.net.parameters(), lr=0.001) | |
train_losses = [] | |
with tqdm.trange(num_batch) as batches: | |
for b in batches: | |
x = self.getdata() | |
# Call network for forward pass | |
losses = self.net(x) |
<!-- For use within a .md file --> | |
{{< rawhtml >}} | |
<video autoplay loop muted playsinline style="max-width:100%"> | |
<source src="images/earth_moon_neural_network_solution_bundle_training.mp4" type="video/mp4"> | |
<img src="images/earth_moon_neural_network_solution_bundle_training.png"> | |
</video> | |
{{< /rawhtml >}} |