You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

neuralnetworks.py 895B

12345678910111213141516171819202122232425262728293031323334353637
  1. ###
  2. '''
  3. Similar to M1 from https://github.com/dpkingma/nips14-ssl
  4. Original Author: S. Saemundsson
  5. Edited by: Z. Rahaie
  6. '''
  7. ###
  8. import tensorflow as tf
  9. import prettytensor as pt
  10. import numpy as np
  11. import utils
  12. class FullyConnected( object ):
  13. def __init__( self,
  14. dim_output,
  15. hidden_layers,
  16. nonlinearity = tf.nn.softplus,
  17. l2loss = 0.0,
  18. name = 'FullyConnected' ):
  19. self.dim_output = dim_output
  20. self.hidden_layers = hidden_layers
  21. self.nonlinearity = nonlinearity
  22. self.l2loss = l2loss
  23. def output( self, inputs, phase = pt.Phase.train ):
  24. inputs = pt.wrap( inputs )
  25. with pt.defaults_scope( phase = phase, activation_fn = self.nonlinearity, l2loss = self.l2loss ):
  26. for layer in self.hidden_layers:
  27. inputs = inputs.fully_connected( layer )
  28. return inputs.fully_connected( self.dim_output, activation_fn = None )