Comments (8)
The trainable
flag sets the parameters associated with that object to be (non)trainable, but you still need to backpropagate the gradient through those objects (to get the gradient for any preceding objects, which may still be trainable). So in your example, even if you set x
to be not trainable, you still get nans
when you propagate the gradient through x
, which results in nans
on the connection weights from stim -> x
. In the second case (configure_settings(trainable=False)
) you're also setting that stim->x
connection to be non-trainable, so you don't end up with nan
weights.
from nengo-dl.
Cool, that clears it all up. Thanks for the quick replies. Feel free to close whenever.
from nengo-dl.
Definitely something weird going on here, I'll dig into it.
from nengo-dl.
Can you try out #27 and see if it works for you?
The problem was that you were getting nans
when computing the gradient of LIFRate
, which TensorFlow was then silently converting into zero output for some reason. Although LIFRate
isn't technically differentiable, we should still be able to compute the gradient without getting nans
, which is what #27 does. But just for your own future work, I'd recommend using nengo_dl.SoftLIFRate
instead, it'll work better during training.
from nengo-dl.
Thanks! This makes sense and works for me. For some reason I had it in the back of my head that nengo_dl
would automatically switch the LIFRate
for SoftLIFRate
to do the optimization and then switch it back. Maybe a way to do this would be useful. If not, then a warning and/or some clip at a maximum value would help this from recurring.
Relatedly... I think I'm misunderstanding how the trainable
config works. I was using this to disable the LIFRate
populations, but that doesn't seem to prevent them from creating problems.
import numpy as np
import matplotlib.pyplot as plt
import nengo
import nengo_dl
import tensorflow as tf
u = np.random.randn(100, 1, 1)
dt = 0.001
with nengo.Network() as model:
stim = nengo.Node(output=nengo.processes.PresentInput(
u, presentation_time=dt))
x = nengo.Ensemble(100, 1, neuron_type=nengo.LIFRate())
y = nengo.Ensemble(100, 1, neuron_type=nengo_dl.SoftLIFRate())
nengo_dl.configure_settings(trainable=True)
model.config[x].trainable = False
#nengo_dl.configure_settings(trainable=False)
#model.config[y].trainable = True
nengo.Connection(stim, x, synapse=None)
nengo.Connection(x, y, synapse=None)
p = nengo.Probe(y, synapse=None)
inputs = {stim: u}
targets = {p: u}
opt = tf.train.MomentumOptimizer(
learning_rate=1e-13, momentum=0.1, use_nesterov=True)
with nengo_dl.Simulator(model, minibatch_size=1, dt=dt) as sim:
sim.train(inputs, targets, opt, n_epochs=1)
sim.run(len(u)*dt)
plt.figure()
plt.plot(sim.trange(), sim.data[p].squeeze())
plt.plot(sim.trange(), u.squeeze(), linestyle='--')
plt.show()
If you switch the two trainable
lines that are commented, it goes from being broken (on master, without #27) to working. But I thought that neither approach would need to differentiate the tuning curves for the x
population.
from nengo-dl.
For some reason I had it in the back of my head that nengo_dl would automatically switch the LIFRate for SoftLIFRate to do the optimization and then switch it back. Maybe a way to do this would be useful.
Yeah that should be possible. I probably wouldn't make it automatic by default, but could probably work up a flag or helper function that'd make that happen.
from nengo-dl.
Thanks for the explanation. To check my understanding, backprop is modifying the scalar transform from stim -> x
to 0
? Or could it even be modifying some other weights (e.g., gains, biases, encoders of x
)?
from nengo-dl.
It's actually setting the transform to nan
in this case (so the output of the network is nan
, but I guess TensorFlow has some logic to convert that to zero).
The gains/biases/encoders are all associated with the trainability of x
, so if you set x
to be non-trainable then they will be fixed. You can use x.neurons
to separately control the trainability of the biases, but you can't separate gains and encoders since those are actually just combined into one parameter in Nengo, the scaled_encoders
. More details in the documentation (in case anyone comes across this discussion in the future).
from nengo-dl.
Related Issues (20)
- AssertionError running custom neuron with TensorFlow 2.3.0 HOT 3
- Empty probes are Python lists instead of ndarrays
- Creating a simulator while keeping pretrained weights HOT 3
- Uninformative error message when using `sim.compile` on a network with no probed outputs
- Support/examples for converting or embedding Keras RNNs HOT 1
- Support scale_firing_rates with Regular/Poisson/Stochastic spiking wrappers
- Warn if converter's scale_firing_rates would skew the nonlinearities
- Support opting in to spikes on the forward pass
- Nengo version of ModelCheckpoint callback
- Use no-input nodes by default in converter
- load_params misbehaves with scale_firing_rates for some architectures HOT 1
- Converter `synapse` not applied to `neurons`-to-`TensorNode` connections HOT 1
- Converter fails with `tf.keras.applications.EfficientNet`
- Mistake in documentation
- Trainable parameters in Nengo LIF neurons HOT 2
- Which neuromorphic hardware does NengoDL simulate ?
- sim.predict make GPU full memory HOT 7
- BatchNormalization layer produces LOW accuracy
- Importing Nengo_DL in Google Colab HOT 1
- `nengo_dl` cannot import `keras.engine` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nengo-dl.