def _get_datasets_and_inputs(outputs): import tensorflow as tf all_required_inputs = find_placeholders(outputs) dataset = tf.get_collection(all_required_inputs[0].name)[0] inputs = dataset.tensors _check_the_same(all_required_inputs, inputs) return dataset, inputs
def _get_arguments_from_loss(loss, optim_method, session, val_outputs, val_labels, val_method): import tensorflow as tf if session is None: sess = tf.Session() sess.run(tf.global_variables_initializer()) else: sess = session grads_vars = tf.train.GradientDescentOptimizer(0).compute_gradients( loss) variables = [] grads = [] for (grad, var) in grads_vars: if grad is not None: variables.append(var) grads.append(grad) all_required_inputs = _find_placeholders([loss]) dataset = tf.get_collection(all_required_inputs[0].name)[0] inputs = nest.flatten(dataset._original_tensors) _check_the_same(all_required_inputs, inputs) return [ loss, optim_method, sess, dataset, inputs, grads, variables, loss.graph, val_outputs, val_labels, val_method ]