Exemple #1
0
def ttrl(x, ranks, n_outputs):
	weight_initializer = tf.contrib.layers.xavier_initializer()

	if(type(n_outputs) == type([])):
		#n_outputs 	[2,2,2,2,2,2]
		#ranks     	[1,1,2,2,3,4,3,2,2,1,1]
		#x 		 	[50,14,14,32]
		#input_shape[14,14,32,2,2,2,2,2,2]
		suffix = np.prod(n_outputs)
		input_shape = x.get_shape().as_list()[1:]+n_outputs
		bias = tf.get_variable("bias_{}".format(np.prod(n_outputs)), shape=(1, np.prod(n_outputs)))

		cores = []

		for i in range(len(input_shape)-1):
			cores.append(tf.get_variable("core_{0}_output_{1}".format(i,suffix), 
				shape = (ranks[i], input_shape[i], ranks[i+1]), 
				initializer = weight_initializer))

		cores.append(tf.get_variable("core_{0}_last_output_{1}".format(i,suffix), 
			shape = (ranks[-2], input_shape[-1], ranks[-1]), 
			initializer = weight_initializer))

		#for c in cores:
		#	print(c.get_shape().as_list())

		regression_weights = TNSR.tt_to_tensor(cores)
		w_minus1 = tf.reshape(regression_weights, [np.prod(input_shape[:3]), np.prod(n_outputs)])
		x_0 = tf.reshape(x, [-1, np.prod(x.get_shape().as_list()[1:])])
		return tf.reshape(tf.add(tf.matmul(x_0, w_minus1) ,bias), [-1]+n_outputs)

	else:
		suffix = n_outputs
		input_shape = x.get_shape().as_list()[1:]
		#bias = tf.get_variable("bias", shape=(1, n_outputs))
		bias = tf.get_variable("bias_{}".format(np.prod(n_outputs)), shape=(1, np.prod(n_outputs)))

		cores = []

		for i in range(1, len(ranks)-1):
			cores.append(tf.get_variable("core_{0}_output_{1}".format(i,suffix), 
				shape = (ranks[i-1], input_shape[i-1], ranks[i]), 
				initializer = weight_initializer))

		cores.append(tf.get_variable("core_{0}_last_output_{1}".format(i,suffix), 
			shape=(ranks[-2],n_outputs,ranks[-1]),
			initializer = weight_initializer))

		regression_weights = TNSR.tt_to_tensor(cores)
		return regression(x, regression_weights, input_shape, bias, n_outputs)
Exemple #2
0
def ttrl(x, ranks, n_outputs):
	weight_initializer = tf.contrib.layers.xavier_initializer()

	suffix = n_outputs
	input_shape = x.get_shape().as_list()[1:]
	bias = tf.get_variable("bias_{}".format(np.prod(n_outputs)), shape=(1, np.prod(n_outputs)))

	cores = []

	for i in range(1, len(ranks)-1):
		cores.append(tf.get_variable("core_{0}_output_{1}".format(i,suffix), 
			shape = (ranks[i-1], input_shape[i-1], ranks[i]), 
			initializer = weight_initializer))

	cores.append(tf.get_variable("core_{0}_last_output_{1}".format(i,suffix), 
		shape=(ranks[-2],n_outputs,ranks[-1]),
		initializer = weight_initializer))

	regression_weights = TNSR.tt_to_tensor(cores)
	return regression(x, regression_weights, input_shape, bias, n_outputs)
Exemple #3
0
def ttrl(x, ranks, n_outputs):
    weight_initializer = tf.contrib.layers.xavier_initializer()

    suffix = n_outputs
    input_shape = x.get_shape().as_list()[1:]
    bias = tf.get_variable("bias_{}".format(np.prod(n_outputs)),
                           shape=(1, np.prod(n_outputs)))

    cores = []

    for i in range(1, len(ranks) - 1):
        cores.append(
            tf.get_variable("core_{0}_output_{1}".format(i, suffix),
                            shape=(ranks[i - 1], input_shape[i - 1], ranks[i]),
                            initializer=weight_initializer))

    cores.append(
        tf.get_variable("core_{0}_last_output_{1}".format(i, suffix),
                        shape=(ranks[-2], n_outputs, ranks[-1]),
                        initializer=weight_initializer))

    regression_weights = TNSR.tt_to_tensor(cores)
    return regression(x, regression_weights, input_shape, bias, n_outputs)