# Tensorflow running error

**URL:** <https://discuss.ai.google.dev/t/tensorflow-running-error/30766>\
**Category:** General Discussion\
**Tags:** help\_request\
**Created:** [June 26, 2021, 1:25pm UTC](https://discuss.ai.google.dev/t/tensorflow-running-error/30766 "2021-06-26T13:25:09Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Computer\_Knowledge\_A](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/computer_knowledge_a/32/7837_2.png) [@Computer\_Knowledge\_A](https://discuss.ai.google.dev/u/Computer_Knowledge_A)\
**Post date:** [June 26, 2021, 1:25pm UTC](https://discuss.ai.google.dev/t/tensorflow-running-error/30766/1 "2021-06-26T13:25:10Z")

</div>

AttributeError: module 'tensorflow.core.framework.types\_pb2 this error giving when i was executing code please help me

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [June 26, 2021, 4:33pm UTC](https://discuss.ai.google.dev/t/tensorflow-running-error/30766/2 "2021-06-26T16:33:14Z")

</div>

We need a little bit of context here. What is your use case?

---

<div class="post-metadata">

**Author:** ![Computer\_Knowledge\_A](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/computer_knowledge_a/32/7837_2.png) [@Computer\_Knowledge\_A](https://discuss.ai.google.dev/u/Computer_Knowledge_A)\
**Post date:** [June 26, 2021, 4:53pm UTC](https://discuss.ai.google.dev/t/tensorflow-running-error/30766/3 "2021-06-26T16:53:36Z")

</div>

Deep Learning tuning and optimization . yesterday it was working ny tensorflow tool but today not ruuning tensorflow library. i am doing this code “Deep Learning tuning and optimization”

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [June 26, 2021, 5:48pm UTC](https://discuss.ai.google.dev/t/tensorflow-running-error/30766/4 "2021-06-26T17:48:29Z")

</div>

What is your TF version? Can you share an minimal example?

---

<div class="post-metadata">

**Author:** ![Computer\_Knowledge\_A](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/computer_knowledge_a/32/7837_2.png) [@Computer\_Knowledge\_A](https://discuss.ai.google.dev/u/Computer_Knowledge_A)\
**Post date:** [June 28, 2021, 1:50pm UTC](https://discuss.ai.google.dev/t/tensorflow-running-error/30766/5 "2021-06-28T13:50:27Z")

</div>

## tf version 2.5 import tensorflow as tf run this code via jupyter show error

AttributeError Traceback (most recent call last)  
 in   
----\> 1 import tensorflow as tf

c:\users\eshant\appdata\local\programs\python\python38\lib\site-packages\tensorflow\__init_\_.py in   
39 import sys as \_sys  
40  
—\> 41 from tensorflow.python.tools import module\_util as \_module\_util  
42 from tensorflow.python.util.lazy\_loader import LazyLoader as \_LazyLoader  
43

c:\users\eshant\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\__init_\_.py in   
44  
45 # Bring in subpackages.  
—\> 46 from tensorflow.python import data  
47 from tensorflow.python import distribute  
48 from tensorflow.python import keras

c:\users\eshant\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\data\__init_\_.py in   
23  
24 # pylint: disable=unused-import  
—\> 25 from tensorflow.python.data import experimental  
26 from tensorflow.python.data.ops.dataset\_ops import AUTOTUNE  
27 from tensorflow.python.data.ops.dataset\_ops import Dataset

c:\users\eshant\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\data\experimental\__init_\_.py in   
97  
98 # pylint: disable=unused-import  
—\> 99 from tensorflow.python.data.experimental import service  
100 from tensorflow.python.data.experimental.ops.batching import dense\_to\_ragged\_batch  
101 from tensorflow.python.data.experimental.ops.batching import dense\_to\_sparse\_batch

c:\users\eshant\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\data\experimental\service\__init_\_.py in   
138 from **future** import print\_function  
139  
 → 140 from tensorflow.python.data.experimental.ops.data\_service\_ops import distribute  
141 from tensorflow.python.data.experimental.ops.data\_service\_ops import from\_dataset\_id  
142 from tensorflow.python.data.experimental.ops.data\_service\_ops import register\_dataset

c:\users\eshant\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\data\experimental\ops\data\_service\_ops.py in   
23  
24 from tensorflow.python import tf2  
—\> 25 from tensorflow.python.data.experimental.ops import compression\_ops  
26 from tensorflow.python.data.experimental.ops.distribute\_options import AutoShardPolicy  
27 from tensorflow.python.data.experimental.ops.distribute\_options import ExternalStatePolicy

c:\users\eshant\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\data\experimental\ops\compression\_ops.py in   
18 from **future** import print\_function  
19  
—\> 20 from tensorflow.python.data.util import structure  
21 from tensorflow.python.ops import gen\_experimental\_dataset\_ops as ged\_ops  
22

c:\users\eshant\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\data\util\structure.py in   
24 import wrapt  
25  
—\> 26 from tensorflow.python.data.util import nest  
27 from tensorflow.python.framework import composite\_tensor  
28 from tensorflow.python.framework import ops

c:\users\eshant\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\data\util\nest.py in   
38 import six as \_six  
39  
—\> 40 from tensorflow.python.framework import sparse\_tensor as \_sparse\_tensor  
41 from tensorflow.python.util import \_pywrap\_utils  
42 from tensorflow.python.util import nest

c:\users\eshant\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\framework\sparse\_tensor.py in   
26 from tensorflow.python import tf2  
27 from tensorflow.python.framework import composite\_tensor  
—\> 28 from tensorflow.python.framework import constant\_op  
29 from tensorflow.python.framework import dtypes  
30 from tensorflow.python.framework import ops

c:\users\eshant\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\framework\constant\_op.py in   
27 from tensorflow.core.framework import types\_pb2  
28 from tensorflow.python.eager import context  
—\> 29 from tensorflow.python.eager import execute  
30 from tensorflow.python.framework import dtypes  
31 from tensorflow.python.framework import op\_callbacks

c:\users\eshant\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\eager\execute.py in   
26 from tensorflow.python.eager import core  
27 from tensorflow.python.framework import dtypes  
—\> 28 from tensorflow.python.framework import ops  
29 from tensorflow.python.framework import tensor\_shape  
30 from tensorflow.python.util import compat

c:\users\eshant\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\framework\ops.py in   
52 from tensorflow.python.framework import c\_api\_util  
53 from tensorflow.python.framework import composite\_tensor  
—\> 54 from tensorflow.python.framework import cpp\_shape\_inference\_pb2  
55 from tensorflow.python.framework import device as pydev  
56 from tensorflow.python.framework import dtypes

c:\users\eshant\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\framework\cpp\_shape\_inference\_pb2.py in   
188 \_CPPSHAPEINFERENCERESULT\_HANDLESHAPEANDTYPE.fields\_by\_name[‘shape’].message\_type = tensorflow\_dot\_core\_dot\_framework\_dot\_tensor\_\_shape\_\_pb2.\_TENSORSHAPEPROTO  
189 \_CPPSHAPEINFERENCERESULT\_HANDLESHAPEANDTYPE.fields\_by\_name[‘dtype’].enum\_type = tensorflow\_dot\_core\_dot\_framework\_dot\_types\_\_pb2.\_DATATYPE  
 → 190 \_CPPSHAPEINFERENCERESULT\_HANDLESHAPEANDTYPE.fields\_by\_name[‘specialized\_type’].enum\_type = tensorflow\_dot\_core\_dot\_framework\_dot\_types\_\_pb2.\_SPECIALIZEDTYPE  
191 \_CPPSHAPEINFERENCERESULT\_HANDLESHAPEANDTYPE.containing\_type = \_CPPSHAPEINFERENCERESULT  
192 \_CPPSHAPEINFERENCERESULT\_HANDLEDATA.fields\_by\_name[‘shape\_and\_type’].message\_type = \_CPPSHAPEINFERENCERESULT\_HANDLESHAPEANDTYPE

AttributeError: module ‘tensorflow.core.framework.types\_pb2’ has no attribute ‘\_SPECIALIZEDTYPE’

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [June 28, 2021, 2:03pm UTC](https://discuss.ai.google.dev/t/tensorflow-running-error/30766/6 "2021-06-28T14:03:24Z")

</div>

Are you using a conda env?

---

<div class="post-metadata">

**Author:** ![Computer\_Knowledge\_A](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/computer_knowledge_a/32/7837_2.png) [@Computer\_Knowledge\_A](https://discuss.ai.google.dev/u/Computer_Knowledge_A)\
**Post date:** [June 28, 2021, 2:16pm UTC](https://discuss.ai.google.dev/t/tensorflow-running-error/30766/7 "2021-06-28T14:16:46Z")

</div>

python jupyter not using conda two days earlier working afterthat giving error

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [June 28, 2021, 2:18pm UTC](https://discuss.ai.google.dev/t/tensorflow-running-error/30766/8 "2021-06-28T14:18:58Z")

</div>

Can you test in a fresh `virtualenv`?

---

<div class="post-metadata">

**Author:** ![Computer\_Knowledge\_A](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/computer_knowledge_a/32/7837_2.png) [@Computer\_Knowledge\_A](https://discuss.ai.google.dev/u/Computer_Knowledge_A)\
**Post date:** [June 28, 2021, 2:19pm UTC](https://discuss.ai.google.dev/t/tensorflow-running-error/30766/9 "2021-06-28T14:19:58Z")

</div>

how can i test please guide me

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [June 28, 2021, 2:24pm UTC](https://discuss.ai.google.dev/t/tensorflow-running-error/30766/10 "2021-06-28T14:24:30Z")

</div>

Check

> **[Install TensorFlow with pip](https://www.tensorflow.org/install/pip#2.-create-a-virtual-environment-recommended)**

---

<div class="post-metadata">

**Author:** ![Computer\_Knowledge\_A](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/computer_knowledge_a/32/7837_2.png) [@Computer\_Knowledge\_A](https://discuss.ai.google.dev/u/Computer_Knowledge_A)\
**Post date:** [June 29, 2021, 11:37am UTC](https://discuss.ai.google.dev/t/tensorflow-running-error/30766/11 "2021-06-29T11:37:43Z")

</div>

thank you very much my tensorflow is working but i m getting another error.  
AttributeError Traceback (most recent call last)  
 in   
2 tf.compat.v1.ConfigProto  
3 tf.executing\_eagerly()  
----\> 4 he\_init = tf.contrib.layers.variance\_scaling\_initializer()  
5 hidden1 = tf.layers.dense(X,n\_hidden1,activation=tf.nn.relu,kernel\_initializer=he\_init,name=“hidden1”)

AttributeError: module ‘tensorflow.compat.v1’ has no attribute ‘contrib’

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [June 29, 2021, 12:10pm UTC](https://discuss.ai.google.dev/t/tensorflow-running-error/30766/12 "2021-06-29T12:10:15Z")

</div>

tf.contrib was removed.

You can use:

> **[tf.keras.initializers.VarianceScaling  |  TensorFlow v2.16.1](https://www.tensorflow.org/api_docs/python/tf/keras/initializers/VarianceScaling)**
>
> Initializer that adapts its scale to the shape of its input tensors.

---

<div class="post-metadata">

**Author:** ![Computer\_Knowledge\_A](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/computer_knowledge_a/32/7837_2.png) [@Computer\_Knowledge\_A](https://discuss.ai.google.dev/u/Computer_Knowledge_A)\
**Post date:** [June 30, 2021, 10:55am UTC](https://discuss.ai.google.dev/t/tensorflow-running-error/30766/13 "2021-06-30T10:55:24Z")

</div>

from tensorflow.examples.tutorials.mnist import input\_data  
#from tensorflow.keras.datasets.mnist import input\_data  
mnist = input\_data.read\_data\_sets(“/tmp/data/”) this code giving error  
in tensorflow 2.5  
ModuleNotFoundError Traceback (most recent call last)  
 in   
----\> 1 from tensorflow.examples.tutorials.mnist import input\_data  
2 #from tensorflow.keras.datasets.mnist import input\_data  
3 mnist = input\_data.read\_data\_sets(“/tmp/data/”)

c:\users\eshant\appdata\local\programs\python\python38\lib\site-packages\tensorflow\examples\tutorials\mnist\__init_\_.py in   
19 from **future** import print\_function  
20  
—\> 21 from tensorflow.examples.tutorials.mnist import input\_data  
22 from tensorflow.examples.tutorials.mnist import mnist

c:\users\eshant\appdata\local\programs\python\python38\lib\site-packages\tensorflow\examples\tutorials\mnist\input\_data.py in   
27 from six.moves import xrange # pylint: disable=redefined-builtin  
28 import tensorflow as tf  
—\> 29 from tensorflow.contrib.learn.python.learn.datasets.mnist import read\_data\_sets

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [June 30, 2021, 12:41pm UTC](https://discuss.ai.google.dev/t/tensorflow-running-error/30766/14 "2021-06-30T12:41:11Z")

</div>

`from tensorflow.examples.tutorials.mnist import input_data`

I don’t think we have this in TF 2.5.

---

<div class="post-metadata">

**Author:** ![Computer\_Knowledge\_A](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/computer_knowledge_a/32/7837_2.png) [@Computer\_Knowledge\_A](https://discuss.ai.google.dev/u/Computer_Knowledge_A)\
**Post date:** [July 8, 2021, 9:05am UTC](https://discuss.ai.google.dev/t/tensorflow-running-error/30766/15 "2021-07-08T09:05:35Z")

</div>

# for each observation in the training set, as test sample

# initialize a dataframe to save all the test run results

df\_loocv = pd.DataFrame()

for index, row in df\_iris.iterrows():  
# save the current in the processed df\_loocv  
df\_loocv = df\_loocv.append(df\_iris.iloc[index: index+1])

```
# drop the current row chosen as test sample
# save it in temp df
df_iris_trim = df_iris.drop(index)

test_sepal_length = float(df_iris.loc[index, ['sepal_length']])
test_sepal_width = float(df_iris.loc[index, ['sepal_width']])
test_petal_length = float(df_iris.loc[index, ['petal_length']])
test_petal_width = float(df_iris.loc[index, ['petal_width']])

# for each row in the dataframe, calculate the distance
for index1, row1 in df_iris_trim.iterrows():
    eucDist = sqrt(((test_sepal_length - float(row1['sepal_length'])) ** 2 +
                    (test_sepal_width - float(row1['sepal_width'])) ** 2 +
                    (test_petal_length - float(row1['petal_length'])) ** 2 +
                    (test_petal_width - float(row1['petal_width'])) ** 2))

    df_iris_trim.loc[index1, 'distance'] = eucDist
    
# sort on distance, ascending.
df_iris_trim.sort_values('distance', ascending=True, inplace=True)

# select the first K rows, into a new df
K = int(K1)
df_iris_trim_K = df_iris_trim.iloc[0:K, :]

# The resulting object will be in descending order so that the first element 
# is the most frequently-occurring element. Excludes NA values by default.
df_iris_trim_K_grouped = df_iris_trim_K['class'].value_counts()

# get the first index of the resulting pandas series above (value_counts)
pred_class = df_iris_trim_K_grouped.index[0]

# save the predicated class in the test data frame
df_loocv.loc[index, 'pred_class'] = pred_class

```

I AM GETTING ERROR THINS ONE FOR SEPAL\_LENGTH, SEPAL\_WIDTH  
KeyError: “None of [Index([‘sepal\_length’], dtype=‘object’)] are in the [index]”
