Tensorflow running error

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

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

1 Like

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”

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

1 Like

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’

Are you using a conda env?

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

Can you test in a fresh virtualenv?

how can i test please guide me

Check

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’

1 Like

tf.contrib was removed.

You can use:

1 Like

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

from tensorflow.examples.tutorials.mnist import input_data

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

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]”