【发布时间】:2021-02-14 21:44:01
【问题描述】:
有人可以帮我解决这个错误吗: ~\anaconda3\lib\site-packages\six.py in raise_from(value, from_value)
InvalidArgumentError: StringToNumberOp could not correctly convert string: [4 [Op:StringToNumber]
我知道我应该将字符串数组转换为浮点数组,但我现在不知道如何?
首先我从我创建的 txt 文件创建一个数据集
data = np.genfromtxt('C:\image echantillon\DATATR',delimiter =',', dtype=str)
X=data[:,0:3]
#X_train = np.asarray(X)
tf.strings.to_number(X, out_type=tf.float32)
Y=data[:,3:]
tf.strings.to_number(Y, out_type=tf.float32)
我尝试使用 tf.strings.to_number(x, out_type=tf.float32) 转换该数据
之后我创建了一个顺序模型
model = Sequential()
model.add(Dense(8, input_dim=3, kernel_initializer='he_uniform', activation='relu'))
model.add(Dense(8, kernel_initializer='he_uniform', activation='relu'))
model.add(Dense(9, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
````
my file look like this
``
['[4' ' 3' ' 5'] [' 1' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0]']
['[4' ' 3' ' 5'] [' 1' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0]']
['[4' ' 3' ' 5'] [' 1' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0]']
['[4' ' 3' ' 4'] [' 1' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0]']
['[4' ' 3' ' 4'] [' 1' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0]']
['[4' ' 3' ' 3'] [' 1' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0]']
['[4' ' 3' ' 3'] [' 1' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0' ' 0]']``
【问题讨论】:
标签: python tensorflow keras