簡體   English   中英

ValueError:無法將字符串轉換為float - python

[英]ValueError: could not convert string to float - python

我是ML的新手。 我創建了一個帶有一些圖像的數據集,用於數字識別。 我想訓練我的模型但是在裝配時我有錯誤。

我試過編碼urls numpy數組,但它不起作用:

le = preprocessing.LabelEncoder()
urls = le.fit_transform(urls) 
import json
import json_lines
import numpy as np
from sklearn.model_selection import train_test_split
import tensorflow as tf
from sklearn import preprocessing
import sklearn

urls=[]
labels =[]

with open('Digits_file.json') as file1:
    lis = []
    for i in json_lines.reader(file1):
        lis.append(i)

for i in lis:
    urls.append(i['content'])
    labels.append([i['annotation']['labels'][0]])

urls = np.array(urls)
labels = np.array(labels) 

x_train, x_test, y_train, y_test = train_test_split(urls, labels, test_size=0.2)


model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten(input_shape=[98,98]))
model.add(tf.keras.layers.Dense(128, activation="relu"))
model.add(tf.keras.layers.Dense(10, activation="softmax"))

model.compile(
    loss="sparse_categorical_crossentropy",
    optimizer="adam",
    metrics=["accuracy"]
)

model.fit(x_train, y_train, epochs=5)

我收到了錯誤:

在----> 1 model.fit(x_train,y_train,epochs = 1)中的ValueError Traceback(最近調用最后一次)ValueError:無法將字符串轉換為float:' http ://com.dataturks.a96-i23.open .s3.amazonaws.com / 2c9fafb06abf8f13016aea188d5c036c / c0e1ad90-fec9-4609-b6d8-65b7efb5263c ___ 0001_CH4M_0_number-25.png '

感謝您的幫助。

首先,String數據可以是x_train數據。

您應該識別用於學習的數據。
從您的代碼,您似乎想要按contents學習annotationlabel
我認為contents是自然語言。

對於基本的NLP(自然語言處理),我們應該做識別過程。 我從其他答案中得到了一些好的答案。 請參考。 https://datascience.stackexchange.com/questions/12695/machine-learning-identification-and-classification-based-on-string-contents-ge

而且,如果訓練數據是圖像,則需要進行其他預處理。 我從其他答案中得到了一些好的答案。 https://datascience.stackexchange.com/questions/5224/how-to-prepare-augment-images-for-neural-network

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM