Python utils.rms() Examples
The following are 30
code examples of utils.rms().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
utils
, or try the search function
.
Example #1
Source File: rebar.py From yolo_v2 with Apache License 2.0 | 6 votes |
def get_nvil_gradient(self): """Compute the NVIL gradient.""" # Hard loss logQHard, samples = self._recognition_network() ELBO, reinforce_model_grad = self._generator_network(samples, logQHard) logQHard = tf.add_n(logQHard) # Add baselines (no variance normalization) learning_signal = tf.stop_gradient(ELBO) - self._create_baseline() # Set up losses self.baseline_loss.append(tf.square(learning_signal)) optimizerLoss = -(tf.stop_gradient(learning_signal)*logQHard + reinforce_model_grad) optimizerLoss = tf.reduce_mean(optimizerLoss) nvil_gradient = self.optimizer_class.compute_gradients(optimizerLoss) debug = { 'ELBO': ELBO, 'RMS of centered learning signal': U.rms(learning_signal), } return nvil_gradient, debug
Example #2
Source File: rebar.py From multilabel-image-classification-tensorflow with MIT License | 6 votes |
def get_nvil_gradient(self): """Compute the NVIL gradient.""" # Hard loss logQHard, samples = self._recognition_network() ELBO, reinforce_model_grad = self._generator_network(samples, logQHard) logQHard = tf.add_n(logQHard) # Add baselines (no variance normalization) learning_signal = tf.stop_gradient(ELBO) - self._create_baseline() # Set up losses self.baseline_loss.append(tf.square(learning_signal)) optimizerLoss = -(tf.stop_gradient(learning_signal)*logQHard + reinforce_model_grad) optimizerLoss = tf.reduce_mean(optimizerLoss) nvil_gradient = self.optimizer_class.compute_gradients(optimizerLoss) debug = { 'ELBO': ELBO, 'RMS of centered learning signal': U.rms(learning_signal), } return nvil_gradient, debug
Example #3
Source File: rebar.py From multilabel-image-classification-tensorflow with MIT License | 6 votes |
def _create_loss(self): # Hard loss logQHard, samples = self._recognition_network() reinforce_learning_signal, reinforce_model_grad = self._generator_network(samples, logQHard) logQHard = tf.add_n(logQHard) # REINFORCE learning_signal = tf.stop_gradient(U.center(reinforce_learning_signal)) self.optimizerLoss = -(learning_signal*logQHard + reinforce_model_grad) self.lHat = map(tf.reduce_mean, [ reinforce_learning_signal, U.rms(learning_signal), ]) return reinforce_learning_signal
Example #4
Source File: rebar.py From models with Apache License 2.0 | 6 votes |
def get_nvil_gradient(self): """Compute the NVIL gradient.""" # Hard loss logQHard, samples = self._recognition_network() ELBO, reinforce_model_grad = self._generator_network(samples, logQHard) logQHard = tf.add_n(logQHard) # Add baselines (no variance normalization) learning_signal = tf.stop_gradient(ELBO) - self._create_baseline() # Set up losses self.baseline_loss.append(tf.square(learning_signal)) optimizerLoss = -(tf.stop_gradient(learning_signal)*logQHard + reinforce_model_grad) optimizerLoss = tf.reduce_mean(optimizerLoss) nvil_gradient = self.optimizer_class.compute_gradients(optimizerLoss) debug = { 'ELBO': ELBO, 'RMS of centered learning signal': U.rms(learning_signal), } return nvil_gradient, debug
Example #5
Source File: rebar.py From models with Apache License 2.0 | 6 votes |
def _create_loss(self): # Hard loss logQHard, samples = self._recognition_network() reinforce_learning_signal, reinforce_model_grad = self._generator_network(samples, logQHard) logQHard = tf.add_n(logQHard) # REINFORCE learning_signal = tf.stop_gradient(U.center(reinforce_learning_signal)) self.optimizerLoss = -(learning_signal*logQHard + reinforce_model_grad) self.lHat = map(tf.reduce_mean, [ reinforce_learning_signal, U.rms(learning_signal), ]) return reinforce_learning_signal
Example #6
Source File: rebar.py From g-tensorflow-models with Apache License 2.0 | 6 votes |
def get_nvil_gradient(self): """Compute the NVIL gradient.""" # Hard loss logQHard, samples = self._recognition_network() ELBO, reinforce_model_grad = self._generator_network(samples, logQHard) logQHard = tf.add_n(logQHard) # Add baselines (no variance normalization) learning_signal = tf.stop_gradient(ELBO) - self._create_baseline() # Set up losses self.baseline_loss.append(tf.square(learning_signal)) optimizerLoss = -(tf.stop_gradient(learning_signal)*logQHard + reinforce_model_grad) optimizerLoss = tf.reduce_mean(optimizerLoss) nvil_gradient = self.optimizer_class.compute_gradients(optimizerLoss) debug = { 'ELBO': ELBO, 'RMS of centered learning signal': U.rms(learning_signal), } return nvil_gradient, debug
Example #7
Source File: rebar.py From g-tensorflow-models with Apache License 2.0 | 6 votes |
def _create_loss(self): # Hard loss logQHard, samples = self._recognition_network() reinforce_learning_signal, reinforce_model_grad = self._generator_network(samples, logQHard) logQHard = tf.add_n(logQHard) # REINFORCE learning_signal = tf.stop_gradient(U.center(reinforce_learning_signal)) self.optimizerLoss = -(learning_signal*logQHard + reinforce_model_grad) self.lHat = map(tf.reduce_mean, [ reinforce_learning_signal, U.rms(learning_signal), ]) return reinforce_learning_signal
Example #8
Source File: rebar.py From object_detection_with_tensorflow with MIT License | 6 votes |
def get_nvil_gradient(self): """Compute the NVIL gradient.""" # Hard loss logQHard, samples = self._recognition_network() ELBO, reinforce_model_grad = self._generator_network(samples, logQHard) logQHard = tf.add_n(logQHard) # Add baselines (no variance normalization) learning_signal = tf.stop_gradient(ELBO) - self._create_baseline() # Set up losses self.baseline_loss.append(tf.square(learning_signal)) optimizerLoss = -(tf.stop_gradient(learning_signal)*logQHard + reinforce_model_grad) optimizerLoss = tf.reduce_mean(optimizerLoss) nvil_gradient = self.optimizer_class.compute_gradients(optimizerLoss) debug = { 'ELBO': ELBO, 'RMS of centered learning signal': U.rms(learning_signal), } return nvil_gradient, debug
Example #9
Source File: rebar.py From object_detection_with_tensorflow with MIT License | 6 votes |
def _create_loss(self): # Hard loss logQHard, samples = self._recognition_network() reinforce_learning_signal, reinforce_model_grad = self._generator_network(samples, logQHard) logQHard = tf.add_n(logQHard) # REINFORCE learning_signal = tf.stop_gradient(U.center(reinforce_learning_signal)) self.optimizerLoss = -(learning_signal*logQHard + reinforce_model_grad) self.lHat = map(tf.reduce_mean, [ reinforce_learning_signal, U.rms(learning_signal), ]) return reinforce_learning_signal
Example #10
Source File: rebar.py From object_detection_kitti with Apache License 2.0 | 6 votes |
def get_nvil_gradient(self): """Compute the NVIL gradient.""" # Hard loss logQHard, samples = self._recognition_network() ELBO, reinforce_model_grad = self._generator_network(samples, logQHard) logQHard = tf.add_n(logQHard) # Add baselines (no variance normalization) learning_signal = tf.stop_gradient(ELBO) - self._create_baseline() # Set up losses self.baseline_loss.append(tf.square(learning_signal)) optimizerLoss = -(tf.stop_gradient(learning_signal)*logQHard + reinforce_model_grad) optimizerLoss = tf.reduce_mean(optimizerLoss) nvil_gradient = self.optimizer_class.compute_gradients(optimizerLoss) debug = { 'ELBO': ELBO, 'RMS of centered learning signal': U.rms(learning_signal), } return nvil_gradient, debug
Example #11
Source File: rebar.py From object_detection_kitti with Apache License 2.0 | 6 votes |
def _create_loss(self): # Hard loss logQHard, samples = self._recognition_network() reinforce_learning_signal, reinforce_model_grad = self._generator_network(samples, logQHard) logQHard = tf.add_n(logQHard) # REINFORCE learning_signal = tf.stop_gradient(U.center(reinforce_learning_signal)) self.optimizerLoss = -(learning_signal*logQHard + reinforce_model_grad) self.lHat = map(tf.reduce_mean, [ reinforce_learning_signal, U.rms(learning_signal), ]) return reinforce_learning_signal
Example #12
Source File: rebar.py From hands-detection with MIT License | 6 votes |
def get_nvil_gradient(self): """Compute the NVIL gradient.""" # Hard loss logQHard, samples = self._recognition_network() ELBO, reinforce_model_grad = self._generator_network(samples, logQHard) logQHard = tf.add_n(logQHard) # Add baselines (no variance normalization) learning_signal = tf.stop_gradient(ELBO) - self._create_baseline() # Set up losses self.baseline_loss.append(tf.square(learning_signal)) optimizerLoss = -(tf.stop_gradient(learning_signal)*logQHard + reinforce_model_grad) optimizerLoss = tf.reduce_mean(optimizerLoss) nvil_gradient = self.optimizer_class.compute_gradients(optimizerLoss) debug = { 'ELBO': ELBO, 'RMS of centered learning signal': U.rms(learning_signal), } return nvil_gradient, debug
Example #13
Source File: rebar.py From yolo_v2 with Apache License 2.0 | 6 votes |
def _create_loss(self): # Hard loss logQHard, samples = self._recognition_network() reinforce_learning_signal, reinforce_model_grad = self._generator_network(samples, logQHard) logQHard = tf.add_n(logQHard) # REINFORCE learning_signal = tf.stop_gradient(U.center(reinforce_learning_signal)) self.optimizerLoss = -(learning_signal*logQHard + reinforce_model_grad) self.lHat = map(tf.reduce_mean, [ reinforce_learning_signal, U.rms(learning_signal), ]) return reinforce_learning_signal
Example #14
Source File: rebar.py From hands-detection with MIT License | 6 votes |
def _create_loss(self): # Hard loss logQHard, samples = self._recognition_network() reinforce_learning_signal, reinforce_model_grad = self._generator_network(samples, logQHard) logQHard = tf.add_n(logQHard) # REINFORCE learning_signal = tf.stop_gradient(center(reinforce_learning_signal)) self.optimizerLoss = -(learning_signal*logQHard + reinforce_model_grad) self.lHat = map(tf.reduce_mean, [ reinforce_learning_signal, U.rms(learning_signal), ]) return reinforce_learning_signal
Example #15
Source File: rebar.py From Gun-Detector with Apache License 2.0 | 6 votes |
def _create_loss(self): # Hard loss logQHard, samples = self._recognition_network() reinforce_learning_signal, reinforce_model_grad = self._generator_network(samples, logQHard) logQHard = tf.add_n(logQHard) # REINFORCE learning_signal = tf.stop_gradient(U.center(reinforce_learning_signal)) self.optimizerLoss = -(learning_signal*logQHard + reinforce_model_grad) self.lHat = map(tf.reduce_mean, [ reinforce_learning_signal, U.rms(learning_signal), ]) return reinforce_learning_signal
Example #16
Source File: rebar.py From Gun-Detector with Apache License 2.0 | 6 votes |
def get_nvil_gradient(self): """Compute the NVIL gradient.""" # Hard loss logQHard, samples = self._recognition_network() ELBO, reinforce_model_grad = self._generator_network(samples, logQHard) logQHard = tf.add_n(logQHard) # Add baselines (no variance normalization) learning_signal = tf.stop_gradient(ELBO) - self._create_baseline() # Set up losses self.baseline_loss.append(tf.square(learning_signal)) optimizerLoss = -(tf.stop_gradient(learning_signal)*logQHard + reinforce_model_grad) optimizerLoss = tf.reduce_mean(optimizerLoss) nvil_gradient = self.optimizer_class.compute_gradients(optimizerLoss) debug = { 'ELBO': ELBO, 'RMS of centered learning signal': U.rms(learning_signal), } return nvil_gradient, debug
Example #17
Source File: rebar.py From hands-detection with MIT License | 5 votes |
def get_simple_muprop_gradient(self): """ Computes the simple muprop gradient. This muprop control variate does not include the linear term. """ # Hard loss logQHard, hardSamples = self._recognition_network() hardELBO, reinforce_model_grad = self._generator_network(hardSamples, logQHard) # Soft loss logQ, muSamples = self._recognition_network(sampler=self._mean_sample) muELBO, _ = self._generator_network(muSamples, logQ) scaling_baseline = self._create_eta(collection='BASELINE') learning_signal = (hardELBO - scaling_baseline * muELBO - self._create_baseline()) self.baseline_loss.append(tf.square(learning_signal)) optimizerLoss = -(tf.stop_gradient(learning_signal) * tf.add_n(logQHard) + reinforce_model_grad) optimizerLoss = tf.reduce_mean(optimizerLoss) simple_muprop_gradient = (self.optimizer_class. compute_gradients(optimizerLoss)) debug = { 'ELBO': hardELBO, 'muELBO': muELBO, 'RMS': U.rms(learning_signal), } return simple_muprop_gradient, debug
Example #18
Source File: rebar.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def get_simple_muprop_gradient(self): """ Computes the simple muprop gradient. This muprop control variate does not include the linear term. """ # Hard loss logQHard, hardSamples = self._recognition_network() hardELBO, reinforce_model_grad = self._generator_network(hardSamples, logQHard) # Soft loss logQ, muSamples = self._recognition_network(sampler=self._mean_sample) muELBO, _ = self._generator_network(muSamples, logQ) scaling_baseline = self._create_eta(collection='BASELINE') learning_signal = (hardELBO - scaling_baseline * muELBO - self._create_baseline()) self.baseline_loss.append(tf.square(learning_signal)) optimizerLoss = -(tf.stop_gradient(learning_signal) * tf.add_n(logQHard) + reinforce_model_grad) optimizerLoss = tf.reduce_mean(optimizerLoss) simple_muprop_gradient = (self.optimizer_class. compute_gradients(optimizerLoss)) debug = { 'ELBO': hardELBO, 'muELBO': muELBO, 'RMS': U.rms(learning_signal), } return simple_muprop_gradient, debug
Example #19
Source File: rebar.py From yolo_v2 with Apache License 2.0 | 5 votes |
def get_simple_muprop_gradient(self): """ Computes the simple muprop gradient. This muprop control variate does not include the linear term. """ # Hard loss logQHard, hardSamples = self._recognition_network() hardELBO, reinforce_model_grad = self._generator_network(hardSamples, logQHard) # Soft loss logQ, muSamples = self._recognition_network(sampler=self._mean_sample) muELBO, _ = self._generator_network(muSamples, logQ) scaling_baseline = self._create_eta(collection='BASELINE') learning_signal = (hardELBO - scaling_baseline * muELBO - self._create_baseline()) self.baseline_loss.append(tf.square(learning_signal)) optimizerLoss = -(tf.stop_gradient(learning_signal) * tf.add_n(logQHard) + reinforce_model_grad) optimizerLoss = tf.reduce_mean(optimizerLoss) simple_muprop_gradient = (self.optimizer_class. compute_gradients(optimizerLoss)) debug = { 'ELBO': hardELBO, 'muELBO': muELBO, 'RMS': U.rms(learning_signal), } return simple_muprop_gradient, debug
Example #20
Source File: rebar.py From models with Apache License 2.0 | 5 votes |
def get_simple_muprop_gradient(self): """ Computes the simple muprop gradient. This muprop control variate does not include the linear term. """ # Hard loss logQHard, hardSamples = self._recognition_network() hardELBO, reinforce_model_grad = self._generator_network(hardSamples, logQHard) # Soft loss logQ, muSamples = self._recognition_network(sampler=self._mean_sample) muELBO, _ = self._generator_network(muSamples, logQ) scaling_baseline = self._create_eta(collection='BASELINE') learning_signal = (hardELBO - scaling_baseline * muELBO - self._create_baseline()) self.baseline_loss.append(tf.square(learning_signal)) optimizerLoss = -(tf.stop_gradient(learning_signal) * tf.add_n(logQHard) + reinforce_model_grad) optimizerLoss = tf.reduce_mean(optimizerLoss) simple_muprop_gradient = (self.optimizer_class. compute_gradients(optimizerLoss)) debug = { 'ELBO': hardELBO, 'muELBO': muELBO, 'RMS': U.rms(learning_signal), } return simple_muprop_gradient, debug
Example #21
Source File: rebar.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def get_simple_muprop_gradient(self): """ Computes the simple muprop gradient. This muprop control variate does not include the linear term. """ # Hard loss logQHard, hardSamples = self._recognition_network() hardELBO, reinforce_model_grad = self._generator_network(hardSamples, logQHard) # Soft loss logQ, muSamples = self._recognition_network(sampler=self._mean_sample) muELBO, _ = self._generator_network(muSamples, logQ) scaling_baseline = self._create_eta(collection='BASELINE') learning_signal = (hardELBO - scaling_baseline * muELBO - self._create_baseline()) self.baseline_loss.append(tf.square(learning_signal)) optimizerLoss = -(tf.stop_gradient(learning_signal) * tf.add_n(logQHard) + reinforce_model_grad) optimizerLoss = tf.reduce_mean(optimizerLoss) simple_muprop_gradient = (self.optimizer_class. compute_gradients(optimizerLoss)) debug = { 'ELBO': hardELBO, 'muELBO': muELBO, 'RMS': U.rms(learning_signal), } return simple_muprop_gradient, debug
Example #22
Source File: rebar.py From Gun-Detector with Apache License 2.0 | 5 votes |
def get_simple_muprop_gradient(self): """ Computes the simple muprop gradient. This muprop control variate does not include the linear term. """ # Hard loss logQHard, hardSamples = self._recognition_network() hardELBO, reinforce_model_grad = self._generator_network(hardSamples, logQHard) # Soft loss logQ, muSamples = self._recognition_network(sampler=self._mean_sample) muELBO, _ = self._generator_network(muSamples, logQ) scaling_baseline = self._create_eta(collection='BASELINE') learning_signal = (hardELBO - scaling_baseline * muELBO - self._create_baseline()) self.baseline_loss.append(tf.square(learning_signal)) optimizerLoss = -(tf.stop_gradient(learning_signal) * tf.add_n(logQHard) + reinforce_model_grad) optimizerLoss = tf.reduce_mean(optimizerLoss) simple_muprop_gradient = (self.optimizer_class. compute_gradients(optimizerLoss)) debug = { 'ELBO': hardELBO, 'muELBO': muELBO, 'RMS': U.rms(learning_signal), } return simple_muprop_gradient, debug
Example #23
Source File: rebar.py From object_detection_with_tensorflow with MIT License | 5 votes |
def get_simple_muprop_gradient(self): """ Computes the simple muprop gradient. This muprop control variate does not include the linear term. """ # Hard loss logQHard, hardSamples = self._recognition_network() hardELBO, reinforce_model_grad = self._generator_network(hardSamples, logQHard) # Soft loss logQ, muSamples = self._recognition_network(sampler=self._mean_sample) muELBO, _ = self._generator_network(muSamples, logQ) scaling_baseline = self._create_eta(collection='BASELINE') learning_signal = (hardELBO - scaling_baseline * muELBO - self._create_baseline()) self.baseline_loss.append(tf.square(learning_signal)) optimizerLoss = -(tf.stop_gradient(learning_signal) * tf.add_n(logQHard) + reinforce_model_grad) optimizerLoss = tf.reduce_mean(optimizerLoss) simple_muprop_gradient = (self.optimizer_class. compute_gradients(optimizerLoss)) debug = { 'ELBO': hardELBO, 'muELBO': muELBO, 'RMS': U.rms(learning_signal), } return simple_muprop_gradient, debug
Example #24
Source File: rebar.py From object_detection_kitti with Apache License 2.0 | 5 votes |
def get_simple_muprop_gradient(self): """ Computes the simple muprop gradient. This muprop control variate does not include the linear term. """ # Hard loss logQHard, hardSamples = self._recognition_network() hardELBO, reinforce_model_grad = self._generator_network(hardSamples, logQHard) # Soft loss logQ, muSamples = self._recognition_network(sampler=self._mean_sample) muELBO, _ = self._generator_network(muSamples, logQ) scaling_baseline = self._create_eta(collection='BASELINE') learning_signal = (hardELBO - scaling_baseline * muELBO - self._create_baseline()) self.baseline_loss.append(tf.square(learning_signal)) optimizerLoss = -(tf.stop_gradient(learning_signal) * tf.add_n(logQHard) + reinforce_model_grad) optimizerLoss = tf.reduce_mean(optimizerLoss) simple_muprop_gradient = (self.optimizer_class. compute_gradients(optimizerLoss)) debug = { 'ELBO': hardELBO, 'muELBO': muELBO, 'RMS': U.rms(learning_signal), } return simple_muprop_gradient, debug
Example #25
Source File: rebar.py From object_detection_with_tensorflow with MIT License | 4 votes |
def get_muprop_gradient(self): """ random sample function that actually returns mean new forward pass that returns logQ as a list can get x_i from samples """ # Hard loss logQHard, hardSamples = self._recognition_network() hardELBO, reinforce_model_grad = self._generator_network(hardSamples, logQHard) # Soft loss logQ, muSamples = self._recognition_network(sampler=self._mean_sample) muELBO, _ = self._generator_network(muSamples, logQ) # Compute gradients muELBOGrads = tf.gradients(tf.reduce_sum(muELBO), [ muSamples[i]['activation'] for i in xrange(self.hparams.n_layer) ]) # Compute MuProp gradient estimates learning_signal = hardELBO optimizerLoss = 0.0 learning_signals = [] for i in xrange(self.hparams.n_layer): dfDiff = tf.reduce_sum( muELBOGrads[i] * (hardSamples[i]['activation'] - muSamples[i]['activation']), axis=1) dfMu = tf.reduce_sum( tf.stop_gradient(muELBOGrads[i]) * tf.nn.sigmoid(hardSamples[i]['log_param']), axis=1) scaling_baseline_0 = self._create_eta(collection='BASELINE') scaling_baseline_1 = self._create_eta(collection='BASELINE') learning_signals.append(learning_signal - scaling_baseline_0 * muELBO - scaling_baseline_1 * dfDiff - self._create_baseline()) self.baseline_loss.append(tf.square(learning_signals[i])) optimizerLoss += ( logQHard[i] * tf.stop_gradient(learning_signals[i]) + tf.stop_gradient(scaling_baseline_1) * dfMu) optimizerLoss += reinforce_model_grad optimizerLoss *= -1 optimizerLoss = tf.reduce_mean(optimizerLoss) muprop_gradient = self.optimizer_class.compute_gradients(optimizerLoss) debug = { 'ELBO': hardELBO, 'muELBO': muELBO, } debug.update(dict([ ('RMS learning signal layer %d' % i, U.rms(learning_signal)) for (i, learning_signal) in enumerate(learning_signals)])) return muprop_gradient, debug # REBAR gradient helper functions
Example #26
Source File: rebar.py From g-tensorflow-models with Apache License 2.0 | 4 votes |
def get_muprop_gradient(self): """ random sample function that actually returns mean new forward pass that returns logQ as a list can get x_i from samples """ # Hard loss logQHard, hardSamples = self._recognition_network() hardELBO, reinforce_model_grad = self._generator_network(hardSamples, logQHard) # Soft loss logQ, muSamples = self._recognition_network(sampler=self._mean_sample) muELBO, _ = self._generator_network(muSamples, logQ) # Compute gradients muELBOGrads = tf.gradients(tf.reduce_sum(muELBO), [ muSamples[i]['activation'] for i in xrange(self.hparams.n_layer) ]) # Compute MuProp gradient estimates learning_signal = hardELBO optimizerLoss = 0.0 learning_signals = [] for i in xrange(self.hparams.n_layer): dfDiff = tf.reduce_sum( muELBOGrads[i] * (hardSamples[i]['activation'] - muSamples[i]['activation']), axis=1) dfMu = tf.reduce_sum( tf.stop_gradient(muELBOGrads[i]) * tf.nn.sigmoid(hardSamples[i]['log_param']), axis=1) scaling_baseline_0 = self._create_eta(collection='BASELINE') scaling_baseline_1 = self._create_eta(collection='BASELINE') learning_signals.append(learning_signal - scaling_baseline_0 * muELBO - scaling_baseline_1 * dfDiff - self._create_baseline()) self.baseline_loss.append(tf.square(learning_signals[i])) optimizerLoss += ( logQHard[i] * tf.stop_gradient(learning_signals[i]) + tf.stop_gradient(scaling_baseline_1) * dfMu) optimizerLoss += reinforce_model_grad optimizerLoss *= -1 optimizerLoss = tf.reduce_mean(optimizerLoss) muprop_gradient = self.optimizer_class.compute_gradients(optimizerLoss) debug = { 'ELBO': hardELBO, 'muELBO': muELBO, } debug.update(dict([ ('RMS learning signal layer %d' % i, U.rms(learning_signal)) for (i, learning_signal) in enumerate(learning_signals)])) return muprop_gradient, debug # REBAR gradient helper functions
Example #27
Source File: rebar.py From yolo_v2 with Apache License 2.0 | 4 votes |
def get_muprop_gradient(self): """ random sample function that actually returns mean new forward pass that returns logQ as a list can get x_i from samples """ # Hard loss logQHard, hardSamples = self._recognition_network() hardELBO, reinforce_model_grad = self._generator_network(hardSamples, logQHard) # Soft loss logQ, muSamples = self._recognition_network(sampler=self._mean_sample) muELBO, _ = self._generator_network(muSamples, logQ) # Compute gradients muELBOGrads = tf.gradients(tf.reduce_sum(muELBO), [ muSamples[i]['activation'] for i in xrange(self.hparams.n_layer) ]) # Compute MuProp gradient estimates learning_signal = hardELBO optimizerLoss = 0.0 learning_signals = [] for i in xrange(self.hparams.n_layer): dfDiff = tf.reduce_sum( muELBOGrads[i] * (hardSamples[i]['activation'] - muSamples[i]['activation']), axis=1) dfMu = tf.reduce_sum( tf.stop_gradient(muELBOGrads[i]) * tf.nn.sigmoid(hardSamples[i]['log_param']), axis=1) scaling_baseline_0 = self._create_eta(collection='BASELINE') scaling_baseline_1 = self._create_eta(collection='BASELINE') learning_signals.append(learning_signal - scaling_baseline_0 * muELBO - scaling_baseline_1 * dfDiff - self._create_baseline()) self.baseline_loss.append(tf.square(learning_signals[i])) optimizerLoss += ( logQHard[i] * tf.stop_gradient(learning_signals[i]) + tf.stop_gradient(scaling_baseline_1) * dfMu) optimizerLoss += reinforce_model_grad optimizerLoss *= -1 optimizerLoss = tf.reduce_mean(optimizerLoss) muprop_gradient = self.optimizer_class.compute_gradients(optimizerLoss) debug = { 'ELBO': hardELBO, 'muELBO': muELBO, } debug.update(dict([ ('RMS learning signal layer %d' % i, U.rms(learning_signal)) for (i, learning_signal) in enumerate(learning_signals)])) return muprop_gradient, debug # REBAR gradient helper functions
Example #28
Source File: rebar.py From Gun-Detector with Apache License 2.0 | 4 votes |
def get_muprop_gradient(self): """ random sample function that actually returns mean new forward pass that returns logQ as a list can get x_i from samples """ # Hard loss logQHard, hardSamples = self._recognition_network() hardELBO, reinforce_model_grad = self._generator_network(hardSamples, logQHard) # Soft loss logQ, muSamples = self._recognition_network(sampler=self._mean_sample) muELBO, _ = self._generator_network(muSamples, logQ) # Compute gradients muELBOGrads = tf.gradients(tf.reduce_sum(muELBO), [ muSamples[i]['activation'] for i in xrange(self.hparams.n_layer) ]) # Compute MuProp gradient estimates learning_signal = hardELBO optimizerLoss = 0.0 learning_signals = [] for i in xrange(self.hparams.n_layer): dfDiff = tf.reduce_sum( muELBOGrads[i] * (hardSamples[i]['activation'] - muSamples[i]['activation']), axis=1) dfMu = tf.reduce_sum( tf.stop_gradient(muELBOGrads[i]) * tf.nn.sigmoid(hardSamples[i]['log_param']), axis=1) scaling_baseline_0 = self._create_eta(collection='BASELINE') scaling_baseline_1 = self._create_eta(collection='BASELINE') learning_signals.append(learning_signal - scaling_baseline_0 * muELBO - scaling_baseline_1 * dfDiff - self._create_baseline()) self.baseline_loss.append(tf.square(learning_signals[i])) optimizerLoss += ( logQHard[i] * tf.stop_gradient(learning_signals[i]) + tf.stop_gradient(scaling_baseline_1) * dfMu) optimizerLoss += reinforce_model_grad optimizerLoss *= -1 optimizerLoss = tf.reduce_mean(optimizerLoss) muprop_gradient = self.optimizer_class.compute_gradients(optimizerLoss) debug = { 'ELBO': hardELBO, 'muELBO': muELBO, } debug.update(dict([ ('RMS learning signal layer %d' % i, U.rms(learning_signal)) for (i, learning_signal) in enumerate(learning_signals)])) return muprop_gradient, debug # REBAR gradient helper functions
Example #29
Source File: rebar.py From models with Apache License 2.0 | 4 votes |
def get_muprop_gradient(self): """ random sample function that actually returns mean new forward pass that returns logQ as a list can get x_i from samples """ # Hard loss logQHard, hardSamples = self._recognition_network() hardELBO, reinforce_model_grad = self._generator_network(hardSamples, logQHard) # Soft loss logQ, muSamples = self._recognition_network(sampler=self._mean_sample) muELBO, _ = self._generator_network(muSamples, logQ) # Compute gradients muELBOGrads = tf.gradients(tf.reduce_sum(muELBO), [ muSamples[i]['activation'] for i in xrange(self.hparams.n_layer) ]) # Compute MuProp gradient estimates learning_signal = hardELBO optimizerLoss = 0.0 learning_signals = [] for i in xrange(self.hparams.n_layer): dfDiff = tf.reduce_sum( muELBOGrads[i] * (hardSamples[i]['activation'] - muSamples[i]['activation']), axis=1) dfMu = tf.reduce_sum( tf.stop_gradient(muELBOGrads[i]) * tf.nn.sigmoid(hardSamples[i]['log_param']), axis=1) scaling_baseline_0 = self._create_eta(collection='BASELINE') scaling_baseline_1 = self._create_eta(collection='BASELINE') learning_signals.append(learning_signal - scaling_baseline_0 * muELBO - scaling_baseline_1 * dfDiff - self._create_baseline()) self.baseline_loss.append(tf.square(learning_signals[i])) optimizerLoss += ( logQHard[i] * tf.stop_gradient(learning_signals[i]) + tf.stop_gradient(scaling_baseline_1) * dfMu) optimizerLoss += reinforce_model_grad optimizerLoss *= -1 optimizerLoss = tf.reduce_mean(optimizerLoss) muprop_gradient = self.optimizer_class.compute_gradients(optimizerLoss) debug = { 'ELBO': hardELBO, 'muELBO': muELBO, } debug.update(dict([ ('RMS learning signal layer %d' % i, U.rms(learning_signal)) for (i, learning_signal) in enumerate(learning_signals)])) return muprop_gradient, debug # REBAR gradient helper functions
Example #30
Source File: rebar.py From object_detection_kitti with Apache License 2.0 | 4 votes |
def get_muprop_gradient(self): """ random sample function that actually returns mean new forward pass that returns logQ as a list can get x_i from samples """ # Hard loss logQHard, hardSamples = self._recognition_network() hardELBO, reinforce_model_grad = self._generator_network(hardSamples, logQHard) # Soft loss logQ, muSamples = self._recognition_network(sampler=self._mean_sample) muELBO, _ = self._generator_network(muSamples, logQ) # Compute gradients muELBOGrads = tf.gradients(tf.reduce_sum(muELBO), [ muSamples[i]['activation'] for i in xrange(self.hparams.n_layer) ]) # Compute MuProp gradient estimates learning_signal = hardELBO optimizerLoss = 0.0 learning_signals = [] for i in xrange(self.hparams.n_layer): dfDiff = tf.reduce_sum( muELBOGrads[i] * (hardSamples[i]['activation'] - muSamples[i]['activation']), axis=1) dfMu = tf.reduce_sum( tf.stop_gradient(muELBOGrads[i]) * tf.nn.sigmoid(hardSamples[i]['log_param']), axis=1) scaling_baseline_0 = self._create_eta(collection='BASELINE') scaling_baseline_1 = self._create_eta(collection='BASELINE') learning_signals.append(learning_signal - scaling_baseline_0 * muELBO - scaling_baseline_1 * dfDiff - self._create_baseline()) self.baseline_loss.append(tf.square(learning_signals[i])) optimizerLoss += ( logQHard[i] * tf.stop_gradient(learning_signals[i]) + tf.stop_gradient(scaling_baseline_1) * dfMu) optimizerLoss += reinforce_model_grad optimizerLoss *= -1 optimizerLoss = tf.reduce_mean(optimizerLoss) muprop_gradient = self.optimizer_class.compute_gradients(optimizerLoss) debug = { 'ELBO': hardELBO, 'muELBO': muELBO, } debug.update(dict([ ('RMS learning signal layer %d' % i, U.rms(learning_signal)) for (i, learning_signal) in enumerate(learning_signals)])) return muprop_gradient, debug # REBAR gradient helper functions