2

I am attempting to create a simple TensorFlow model for learning purposes and I have run into an error I cannot seem to shake. I keep receiving the error:

Unimplemented: Cast string to float is not supported

in reference to either my data or labels or both. I have been trying to ensure both are either floats or a data type that would be easily casted to a float but I am facing difficulty in doing so. Code and full stack trace below. Thanks!

Code:

import tensorflow as tf
import random as rand
import csv
import pandas as pd
import numpy as np

with open('data2.csv', mode='w') as csv_file:
    fieldname = ['sequences', 'classification']
    writer = csv.writer(csv_file, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL)

    mainList = []
    for i in range(1000):
        list = []
        for i in range(100):
            list.append(rand.randint(-10, 10))

        mainList.append(list)

    classlist = []

    for i in range(len(mainList)):
        mus = 0
        for k in range(len(mainList[i])):
            mus += mainList[i][k]
            if -10 < mus < 10:
                classification = 0

            if mus < -10:
                classification = -1

            if 10 < mus:
                classification = 1

        classlist.append(classification)
    writer.writerow(['sequences', 'classification'])
    for l in range(1000):
        writer.writerow([mainList[l], classlist[l]])

    data = pd.read_csv("data2.csv")

    print(data.head())
    data2 = data.copy()
    labels = data2.pop('classification')

    labels = pd.to_numeric(labels)
    print(type(labels))
    print(labels)

    data2 = np.array(data2)
    model = tf.keras.Sequential()
    model.add(tf.keras.layers.Dense(64))
    model.add(tf.keras.layers.Dense(1))

    model.compile(loss=tf.losses.mean_squared_error, optimizer=tf.keras.optimizers.Adam())

    model.fit(data2, labels, epochs=20)

Stack Trace:

2020-12-17 14:17:36.696764: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library nvcuda.dll
2020-12-17 14:17:36.719715: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties: 
pciBusID: 0000:26:00.0 name: GeForce GTX 1050 Ti computeCapability: 6.1
coreClock: 1.43GHz coreCount: 6 deviceMemorySize: 4.00GiB deviceMemoryBandwidth: 104.43GiB/s
2020-12-17 14:17:36.720379: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-12-17 14:17:36.721015: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cublas64_10.dll'; dlerror: cublas64_10.dll not found
2020-12-17 14:17:36.721516: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cufft64_10.dll'; dlerror: cufft64_10.dll not found
2020-12-17 14:17:36.722012: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'curand64_10.dll'; dlerror: curand64_10.dll not found
2020-12-17 14:17:36.722515: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cusolver64_10.dll'; dlerror: cusolver64_10.dll not found
2020-12-17 14:17:36.723084: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cusparse64_10.dll'; dlerror: cusparse64_10.dll not found
2020-12-17 14:17:36.723583: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found
2020-12-17 14:17:36.723692: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1753] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2020-12-17 14:17:36.724333: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-12-17 14:17:36.731641: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x2807f7dca40 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-12-17 14:17:36.731767: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-12-17 14:17:36.731920: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-12-17 14:17:36.732000: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263]      
Epoch 1/20
2020-12-17 14:17:37.021307: W tensorflow/core/framework/op_kernel.cc:1744] OP_REQUIRES failed at cast_op.cc:124 : Unimplemented: Cast string to float is not supported
Traceback (most recent call last):
  File "C:/Users/Michael/PycharmProjects/pythonProject3/Attempt2.py", line 56, in <module>
    model.fit(data2, labels, epochs=20)
  File "C:\Users\Michael\.conda\envs\pythonProject3\lib\site-packages\tensorflow\python\keras\engine\training.py", line 108, in _method_wrapper
    return method(self, *args, **kwargs)
  File "C:\Users\Michael\.conda\envs\pythonProject3\lib\site-packages\tensorflow\python\keras\engine\training.py", line 1098, in fit
    tmp_logs = train_function(iterator)
  File "C:\Users\Michael\.conda\envs\pythonProject3\lib\site-packages\tensorflow\python\eager\def_function.py", line 780, in __call__
    result = self._call(*args, **kwds)
  File "C:\Users\Michael\.conda\envs\pythonProject3\lib\site-packages\tensorflow\python\eager\def_function.py", line 840, in _call
    return self._stateless_fn(*args, **kwds)
  File "C:\Users\Michael\.conda\envs\pythonProject3\lib\site-packages\tensorflow\python\eager\function.py", line 2829, in __call__
    return graph_function._filtered_call(args, kwargs)  # pylint: disable=protected-access
  File "C:\Users\Michael\.conda\envs\pythonProject3\lib\site-packages\tensorflow\python\eager\function.py", line 1843, in _filtered_call
    return self._call_flat(
  File "C:\Users\Michael\.conda\envs\pythonProject3\lib\site-packages\tensorflow\python\eager\function.py", line 1923, in _call_flat
    return self._build_call_outputs(self._inference_function.call(
  File "C:\Users\Michael\.conda\envs\pythonProject3\lib\site-packages\tensorflow\python\eager\function.py", line 545, in call
    outputs = execute.execute(
  File "C:\Users\Michael\.conda\envs\pythonProject3\lib\site-packages\tensorflow\python\eager\execute.py", line 59, in quick_execute
    tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
tensorflow.python.framework.errors_impl.UnimplementedError:  Cast string to float is not supported
     [[node sequential/dense/Cast (defined at /Users/Michael/PycharmProjects/pythonProject3/Attempt2.py:56) ]] [Op:__inference_train_function_546]

Function call stack:
train_function


  • Similar issue https://stackoverflow.com/questions/40186722/cast-string-to-float-is-not-supported-in-linear-model may help you to fix your issue. –  Jan 06 '21 at 07:52

0 Answers0