# From\_tensor\_slice error

**URL:** <https://discuss.ai.google.dev/t/from-tensor-slice-error/27139>\
**Category:** General Discussion\
**Tags:** keras, tf-v1, tfdata, help\_request\
**Created:** [July 21, 2021, 10:53am UTC](https://discuss.ai.google.dev/t/from-tensor-slice-error/27139 "2021-07-21T10:53:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anar\_Abiyev](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/anar_abiyev/32/6859_2.png) [@Anar\_Abiyev](https://discuss.ai.google.dev/u/Anar_Abiyev)\
**Post date:** [July 21, 2021, 10:53am UTC](https://discuss.ai.google.dev/t/from-tensor-slice-error/27139/1 "2021-07-21T10:53:51Z")

</div>

Hi,

This is my code and the error I get when I use “from\_tensor\_slice”. Anyone knows the solution (Keras clear\_output doesn’t help)?

```
import tensorflow as tf 
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split

tf.compat.v1.disable_eager_execution()

df = pd.read_csv('insurance.csv')
X = pd.get_dummies(df, columns = ['sex', 'smoker', 'region'])
y = X.pop('charges')

ds = tf.data.Dataset.from_tensor_slices((X.values, y.values))

```

The error:  
Traceback (most recent call last):  
File “C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-  
packages\tensorflow\python\training\tracking\tracking.py”, line 269, in **del**  
File “C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-  
packages\tensorflow\python\framework\ops.py”, line 4011, in as\_default  
AttributeError: ‘NoneType’ object has no attribute ‘get\_controller’

---

<div class="post-metadata">

**Author:** ![Ashwini\_Gadag](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Ashwini\_Gadag](https://discuss.ai.google.dev/u/Ashwini_Gadag)\
**Post date:** [October 29, 2021, 1:16am UTC](https://discuss.ai.google.dev/t/from-tensor-slice-error/27139/3 "2021-10-29T01:16:13Z")

</div>

The given code is working as expected. Looks like data has some NAN values. Make sure address all the NAN values before converting it to tf.data.Dataset.

> import tensorflow as tf  
> import numpy as np  
> import matplotlib.pyplot as plt  
> import pandas as pd  
> from sklearn.model\_selection import train\_test\_split
> 
> tf.compat.v1.disable\_eager\_execution()
> 
> #df = pd.read\_csv(‘insurance.csv’)  
> #X = pd.get\_dummies(df, columns = [‘sex’, ‘smoker’, ‘region’])  
> #y = X.pop(‘charges’)
> 
> data = {‘sex’:[‘female’, ‘male’, ‘female’, ‘male’],  
> ‘Age’:[‘yes’, ‘no’, ‘no’,‘yes’],  
> ‘region’:[‘USA’,‘India’,‘India’,‘USA’]}
> 
> data1 = {‘charges’:[100,200,300,400]}
> 
> Create DataFrame  
> X = pd.DataFrame(data)  
> y = pd.DataFrame(data1)
> 
> ds = tf.data.Dataset.from\_tensor\_slices((X.values, y.values))

**Output**

> \<TensorSliceDataset shapes: ((3,), (1,)), types: (tf.string, tf.int64)\>
