Tobias
Tobias

Reputation: 1910

Strange graph for convolutional networks

when I construct a convolutional model, I get a very strange resulting graph in TensorBoard. As you can see, the second convolutional layer not only gets the pooling layer as input, but also another convolutional layer. In my opinion and according to my web research, this should be a straight vertical graph with one input and one output per layer (except the very first and last ones).

Am I doing anything wrong or where does this second input come from?

Thank you very much, Tobias

Used model function:

def model_fn(features, labels, mode, params):
    is_training = (mode == tf.estimator.ModeKeys.TRAIN)

    reshaped_features = tf.reshape(features, (-1, features.shape[1], 1))

    # Yes, I have only 1d input to my conv network
    conv1 = tf.layers.conv1d(reshaped_features, filters=10, kernel_size=5)
    pool1 = tf.layers.max_pooling1d(conv1, pool_size=3, strides=1)
    conv2 = tf.layers.conv1d(pool1, filters=10, kernel_size=5)
    conv_2_flat = tf.contrib.layers.flatten(conv2)

    logits = fully_connected(conv_2_flat, 2)

    if mode == tf.estimator.ModeKeys.PREDICT:
        return tf.estimator.EstimatorSpec(
            mode=mode,
            predictions={'logits': logits})

    loss = tf.losses.sparse_softmax_cross_entropy(labels=labels, logits=logits)

    eval_metric_ops = {
            'accuracy': tf.metrics.mean(tf.nn.in_top_k(predictions=logits, targets=labels, k=1)),
    }

    optimizer = tf.train.AdamOptimizer(params['learning_rate'])
    training_op = optimizer.minimize(loss)

    return tf.estimator.EstimatorSpec(
        mode=mode,
        loss=loss,
        train_op=training_op,
        eval_metric_ops=eval_metric_ops)

The resulting graph:

enter image description here

Upvotes: 1

Views: 67

Answers (1)

Sunreef
Sunreef

Reputation: 4542

I used to have very strange connections appearing in Tensorboard as well. I think it is only a bug in the display, not an actual mistake in the architecture.

Giving unique names to my layers solved the problem for me. Declare your layers with a name parameter:

    conv1 = tf.layers.conv1d(reshaped_features, filters=10, kernel_size=5, name="conv1")

Tell me if this solves your problem.

Upvotes: 1

Related Questions