# Data visualisation code with data augmentation layer

**URL:** <https://community.deeplearning.ai/t/data-visualisation-code-with-data-augmentation-layer/404394>\
**Category:** Convolutional Neural Networks in TensorFlow\
**Tags:** week-module-1\
**Created:** [August 1, 2023, 10:59am UTC](https://community.deeplearning.ai/t/data-visualisation-code-with-data-augmentation-layer/404394 "2023-08-01T10:59:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam\_Richard-Bollans](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@Adam\_Richard-Bollans](https://community.deeplearning.ai/u/Adam_Richard-Bollans)\
**Post date:** [August 1, 2023, 10:59am UTC](https://community.deeplearning.ai/t/data-visualisation-code-with-data-augmentation-layer/404394/1 "2023-08-01T10:59:41Z")

</div>

Following the code given [here](https://github.com/https-deeplearning-ai/tensorflow-1-public/blob/main/C2/W1/ungraded_lab/C2_W1_Lab_1_cats_vs_dogs.ipynb) for Visualizing Intermediate Representations, I am running:

```auto
successive_outputs = [layer.output for layer in CNN_model.layers]
visualization_model = tf.keras.models.Model(inputs=CNN_model.inputs, outputs=successive_outputs)

```

but keep getting the error ‘ValueError: Graph disconnected: cannot obtain value for tensor KerasTensor(type\_spec=TensorSpec(shape=(None, 200, 200, 3), dtype=tf.float32, name=‘random\_flip\_input’)…’

The model contains some data augmentation layers which I think are causing the issue. Model is built with:

```auto
CNN_model = tf.keras.Sequential([
        tf.keras.layers.Rescaling(1. / 255),
        data_augmentation,

        # Add convolutions and max pooling
        tf.keras.layers.Conv2D(16, 3, padding='same', activation='relu'),
        tf.keras.layers.MaxPooling2D(),
        tf.keras.layers.Conv2D(32, 3, padding='same', activation='relu'),
        tf.keras.layers.MaxPooling2D(),
        tf.keras.layers.Conv2D(64, 3, padding='same', activation='relu'),
        tf.keras.layers.MaxPooling2D(),
        tf.keras.layers.Dropout(0.2),
        tf.keras.layers.Flatten(),
        tf.keras.layers.Dense(128, activation='relu'),
        tf.keras.layers.Dense(1, activation='sigmoid')
    ])
# Compile the model
CNN_model.compile(loss='binary_crossentropy', optimizer=RMSprop(),
                  metrics=[tf.keras.metrics.BinaryAccuracy(), tf.keras.metrics.Precision(name='precision')])

# Train the model
epochs = 1 # how long to train for
CNN_model.fit(
        train_ds,
        validation_data=val_ds,
        epochs=epochs
    )

```

What is the appropriate way for me to ignore the augmentation layers when trying to visualise the feature maps?

---

<div class="post-metadata">

**Author:** ![saifkhanengr](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/saifkhanengr/32/152858_2.png) [@saifkhanengr](https://community.deeplearning.ai/u/saifkhanengr)\
**Post date:** [August 1, 2023, 11:03am UTC](https://community.deeplearning.ai/t/data-visualisation-code-with-data-augmentation-layer/404394/2 "2023-08-01T11:03:35Z")

</div>

Which course, week, and assignment are you doing? Or is it your personal project?

---

<div class="post-metadata">

**Author:** ![Adam\_Richard-Bollans](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@Adam\_Richard-Bollans](https://community.deeplearning.ai/u/Adam_Richard-Bollans)\
**Post date:** [August 1, 2023, 11:05am UTC](https://community.deeplearning.ai/t/data-visualisation-code-with-data-augmentation-layer/404394/3 "2023-08-01T11:05:32Z")

</div>

From Course 2 Week 1 but adapted for a personal project

---

<div class="post-metadata">

**Author:** ![saifkhanengr](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/saifkhanengr/32/152858_2.png) [@saifkhanengr](https://community.deeplearning.ai/u/saifkhanengr)\
**Post date:** [August 1, 2023, 11:18am UTC](https://community.deeplearning.ai/t/data-visualisation-code-with-data-augmentation-layer/404394/4 "2023-08-01T11:18:16Z")

</div>

Ohk. It is TF1 course 2.

> [@Adam\_Richard-Bollans](#):
>
> What is the appropriate way for me to ignore the augmentation layers when trying to visualise the feature maps?

I am sorry but I don’t have the answer to this question. Maybe duplicating the model but without augmentation. I am not sure.

---

<div class="post-metadata">

**Author:** ![Adam\_Richard-Bollans](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@Adam\_Richard-Bollans](https://community.deeplearning.ai/u/Adam_Richard-Bollans)\
**Post date:** [August 1, 2023, 11:37am UTC](https://community.deeplearning.ai/t/data-visualisation-code-with-data-augmentation-layer/404394/5 "2023-08-01T11:37:56Z")

</div>

I think I have fixed this by just changing the outputs to only include appropriate layers:

```auto
successive_outputs = [layer.output for layer in CNN_model.layers if
                          'conv' in layer.name or 'max_pooling' in layer.name] # only extract features from conv/pool layers

```

---

<div class="post-metadata">

**Author:** ![saifkhanengr](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/saifkhanengr/32/152858_2.png) [@saifkhanengr](https://community.deeplearning.ai/u/saifkhanengr)\
**Post date:** [August 1, 2023, 11:44am UTC](https://community.deeplearning.ai/t/data-visualisation-code-with-data-augmentation-layer/404394/6 "2023-08-01T11:44:46Z")

</div>

That’s great…
