Could not find variable Conv_Pool_7/kernel_7. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Container localhost does not exist. (Could not find resource: localhost/Conv_Pool_7/kernel_7)
@arpithavijay,
Could you please provide complete standalone code to reproduce the issue which helps to debug the issue in an effective way. Also I suspect you are trying to execute the code which is in tensorflow 1.x version. For executing the v1.x code in tensorflow 2.6, you need to make some changes accordingly.

Also I tried to execute sample code of handwriting recognition code using cnn and I was able to get the required output. Kindly find the gist of it [here](https://colab.research.google.com/gist/kiransair/f93a3cfce17ec1058643bf46d6209d0d/mnist.ipynb)

Reference: https://github.com/tensorflow/tensorflow/issues/51141

Thank you!

 the original code was in tf 1.x version, i modified the code to 2.6 [Uploading Tensorflow_problem.txt…]()
 @arpithavijay,
AFAIK some of the api's which were on the code still related to 1.x version which might be leading to the mentioned error. I tried to execute a sample code of handwriting recognition code using cnn and I was able to get the required output. Kindly find the gist of it [here](https://colab.research.google.com/gist/kiransair/f93a3cfce17ec1058643bf46d6209d0d/mnist.ipynb). Could you please re-check and try to convert to the latest tensorflow version and execute the code.

Migration document of tensorflow 1.x to 2.x for the reference. https://www.tensorflow.org/guide/migrate
 Thank you! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/64025">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/64025">No</a>

### Issue type

Support

### Have you reproduced the bug with TensorFlow Nightly?

No

### Source

source

### TensorFlow version

2.6

### Custom code

Yes

### OS platform and distribution

Windows

### Mobile device

_No response_

### Python version

3.9

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

Running handwriting recognition code using cnn and tensorflow, getting the below error : Could not find variable Conv_Pool_7/kernel_7. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Container localhost does not exist. (Could not find resource: localhost/Conv_Pool_7/kernel_7)


Code:  def setupCNN(self):
        cnnIn4d = self.inputImgs
        num_layers = 7  # Number of convolution-pooling layers

    # Define the parameters for each layer
        layer_params = [
            (5, 1, 64),   # Conv_Pool_1
            (5, 64, 128), # Conv_Pool_2
            (3, 128, 128),# Conv_Pool_BN_3
            (3, 128, 256),# Conv_4
            (3, 256, 256),# Conv_Pool_5
            (3, 256, 512),# Conv_Pool_BN_6
            (3, 512, 512) # Conv_Pool_7
        ]

        pool = cnnIn4d  # Initial input to the first CNN layer

    # Create layers using a loop
        for i in range(num_layers):
            with tf.name_scope(f'Conv_Pool_{i+1}'):
                kernel = tf.Variable(tf.random.truncated_normal([layer_params[i][0], layer_params[i][0], layer_params[i][1], layer_params[i][2]], stddev=0.1), name=f'kernel_{i+1}')
                conv = tf.nn.conv2d(pool, kernel, padding='SAME', strides=(1, 1, 1, 1))
                learelu = tf.nn.leaky_relu(conv, alpha=0.01)
                pool = tf.nn.max_pool2d(learelu, ksize=(1, 2, 2, 1), strides=(1, 2, 2, 1), padding='SAME')

        self.cnnOut4d = pool

### Standalone code to reproduce the issue

```shell
def setupCNN(self):
        cnnIn4d = self.inputImgs
        num_layers = 7  # Number of convolution-pooling layers

    # Define the parameters for each layer
        layer_params = [
            (5, 1, 64),   # Conv_Pool_1
            (5, 64, 128), # Conv_Pool_2
            (3, 128, 128),# Conv_Pool_BN_3
            (3, 128, 256),# Conv_4
            (3, 256, 256),# Conv_Pool_5
            (3, 256, 512),# Conv_Pool_BN_6
            (3, 512, 512) # Conv_Pool_7
        ]

        pool = cnnIn4d  # Initial input to the first CNN layer

    # Create layers using a loop
        for i in range(num_layers):
            with tf.name_scope(f'Conv_Pool_{i+1}'):
                kernel = tf.Variable(tf.random.truncated_normal([layer_params[i][0], layer_params[i][0], layer_params[i][1], layer_params[i][2]], stddev=0.1), name=f'kernel_{i+1}')
                conv = tf.nn.conv2d(pool, kernel, padding='SAME', strides=(1, 1, 1, 1))
                learelu = tf.nn.leaky_relu(conv, alpha=0.01)
                pool = tf.nn.max_pool2d(learelu, ksize=(1, 2, 2, 1), strides=(1, 2, 2, 1), padding='SAME')

        self.cnnOut4d = pool
```


### Relevant log output

_No response_