def chooseModel(opts): print('selecting model to test...') if 'cnn' == opts.model: if 'onlyIncoming' == opts.mode: params = cnn.generate_default_onlyIncoming_params(opts.dataType) else: params = cnn.generate_default_whole_params(opts.dataType) modelObj = cnn.CNN(opts, params) elif 'cudnnLstm' == opts.model: if 'onlyIncoming' == opts.mode: params = cudnnLstm.generate_default_onlyIncoming_params(opts.dataType) else: params = cudnnLstm.generate_default_whole_params(opts.dataType) modelObj = cudnnLstm.LSTM(opts, params) elif 'sae' == opts.model: if 'onlyIncoming' == opts.mode: params = sae.generate_default_onlyIncoming_params(opts.dataType) else: params = sae.generate_default_whole_params(opts.dataType) modelObj = sae.SAE(opts, params) return params, modelObj
def chooseModel(opts, ifTest=True, NUM_CLASS=100, modelPath=''): if 'cnn' == opts.model: if 'onlyIncoming' == opts.mode: params = cnn.generate_default_onlyIncoming_params(opts.dataType) else: params = cnn.generate_default_whole_params(opts.dataType) modelObj = cnn.CNN(opts, params) elif 'cudnnLstm' == opts.model: if 'onlyIncoming' == opts.mode: params = cudnnLstm.generate_default_onlyIncoming_params(opts.dataType) else: params = cudnnLstm.generate_default_whole_params(opts.dataType) modelObj = cudnnLstm.LSTM(opts, params) elif 'sae' == opts.model: if 'onlyIncoming' == opts.mode: params = sae.generate_default_onlyIncoming_params(opts.dataType) else: params = sae.generate_default_whole_params(opts.dataType) modelObj = sae.SAE(opts, params) if ifTest: modelObj = modelObj.create_model(NUM_CLASS) modelObj.load_weights(modelPath) return modelObj, params
def __init__(self, opts, params, networkName='SAE'): self.networkName = networkName self.verbose = opts.verbose self.sae_model = sae.SAE(opts, params)
mnist = datamodel.nus_wide_class(batch_size) dims = [500, 128, 32] graph = tf.Graph() with graph.as_default(): w_init_func = tf.random_normal b_init_func = tf.random_normal def loss_func(x, y): return 0.5 * tf.reduce_mean(tf.pow(x - y, 2)) reg_fac = 0.1 act_func = tf.sigmoid sae = sae.SAE(dims, w_init_func, b_init_func, loss_func, act_func, input, reg_fac) input = tf.placeholder('float32', [None, dims[0]]) loss = sae.loss_sae(input) v_error = sae.loss_sae(mnist.valid.images) optimizer = tf.train.AdamOptimizer(learning_rate=0.01).minimize(loss) init = tf.global_variables_initializer() print('model constructed') # Launch the graph with tf.Session(graph=graph) as sess: last_loss = 0 sess.run(init)