def build(self): # Create target inputs self.label_placeholder = Input(tensor=K.placeholder( shape=(None,self.n_tasks), name="label_placeholder", dtype='bool')) self.weight_placeholder = Input(tensor=K.placeholder( shape=(None,self.n_tasks), name="weight_placholder", dtype='float32')) # Create final dense layer from keras feat = self.model.return_outputs() output = model_ops.multitask_logits( feat, self.n_tasks) return output
def build(self): # Create target inputs self.label_placeholder = Input(tensor=K.placeholder( shape=(None,self.n_tasks), name="label_placeholder", dtype='bool')) self.weight_placeholder = Input(tensor=K.placeholder( shape=(None,self.n_tasks), name="weight_placholder", dtype='float32')) # Create final dense layer from keras feat = self.model.return_outputs() output = model_ops.multitask_logits( feat, self.n_tasks) return output
def build(self, graph, name_scopes, training): """Constructs the graph architecture as specified in its config. This method creates the following Placeholders: mol_features: Molecule descriptor (e.g. fingerprint) tensor with shape batch_size x n_features. """ placeholder_scope = TensorflowGraph.get_placeholder_scope( graph, name_scopes) n_features = self.n_features with graph.as_default(): with placeholder_scope: self.mol_features = tf.placeholder( tf.float32, shape=[None, n_features], name='mol_features') layer_sizes = self.layer_sizes weight_init_stddevs = self.weight_init_stddevs bias_init_consts = self.bias_init_consts dropouts = self.dropouts lengths_set = { len(layer_sizes), len(weight_init_stddevs), len(bias_init_consts), len(dropouts), } assert len(lengths_set) == 1, 'All layer params must have same length.' n_layers = lengths_set.pop() assert n_layers > 0, 'Must have some layers defined.' prev_layer = self.mol_features prev_layer_size = n_features for i in range(n_layers): layer = tf.nn.relu(model_ops.fully_connected_layer( tensor=prev_layer, size=layer_sizes[i], weight_init=tf.truncated_normal( shape=[prev_layer_size, layer_sizes[i]], stddev=weight_init_stddevs[i]), bias_init=tf.constant(value=bias_init_consts[i], shape=[layer_sizes[i]]))) layer = model_ops.dropout(layer, dropouts[i], training) prev_layer = layer prev_layer_size = layer_sizes[i] output = model_ops.multitask_logits( layer, self.n_tasks) return output
def build(self, graph, name_scopes, training): """Constructs the graph architecture as specified in its config. This method creates the following Placeholders: mol_features: Molecule descriptor (e.g. fingerprint) tensor with shape batch_size x n_features. """ placeholder_scope = TensorflowGraph.get_placeholder_scope( graph, name_scopes) n_features = self.n_features with graph.as_default(): with placeholder_scope: self.mol_features = tf.placeholder(tf.float32, shape=[None, n_features], name='mol_features') layer_sizes = self.layer_sizes weight_init_stddevs = self.weight_init_stddevs bias_init_consts = self.bias_init_consts dropouts = self.dropouts lengths_set = { len(layer_sizes), len(weight_init_stddevs), len(bias_init_consts), len(dropouts), } assert len( lengths_set) == 1, 'All layer params must have same length.' n_layers = lengths_set.pop() assert n_layers > 0, 'Must have some layers defined.' prev_layer = self.mol_features prev_layer_size = n_features for i in range(n_layers): layer = tf.nn.relu( model_ops.fully_connected_layer( tensor=prev_layer, size=layer_sizes[i], weight_init=tf.truncated_normal( shape=[prev_layer_size, layer_sizes[i]], stddev=weight_init_stddevs[i]), bias_init=tf.constant(value=bias_init_consts[i], shape=[layer_sizes[i]]))) layer = model_ops.dropout(layer, dropouts[i], training) prev_layer = layer prev_layer_size = layer_sizes[i] output = model_ops.multitask_logits(layer, self.n_tasks) return output
def test_multitask_logits(self): with self.test_session() as sess: num_tasks = 3 np.random.seed(FLAGS.test_random_seed) features = np.random.random((5, 100)) logits_t = model_ops.multitask_logits( tf.constant(features, dtype=tf.float32), num_tasks) sess.run(tf.initialize_all_variables()) output = sess.run(tf.trainable_variables() + logits_t) w = output[0:-3:2] b = output[1:-3:2] logits = output[-3:] for i in range(num_tasks): expected = np.dot(features, w[i]) + b[i] self.assertAllClose(logits[i], expected, rtol=1e-5, atol=1e-5)