【发布时间】:2021-02-07 22:19:49
【问题描述】:
我想为输入到 TF 创建一个输入数据集,但被卡住了。我有一个各种输入类型(浮点和字符串)的 csv 文件。我想为 tensorflow 创建一个训练文件。有什么方法可以使用 pandas 或 TF 函数来输入这两种类型的数据
`df = pd.read_csv("C:\TRAININGDATA\DATABASE.csv")
Labeldata = pd.DataFrame(df, columns= ['ASSEMBLY_NAME','x','x','x','x','x','x','x','x','x','x','x'])
#REMOVE DOWN IF YOU WANT ALL DATA IN CSV
#print (Labeldata)
# PRINT CSV DATA FOR THE SPECIFIC ASSEMBLY
ASSEMBLYNAME = 'scene0011_00_vh_clean_2'
labels = df.loc[df['ASSEMBLY_NAME'] == ASSEMBLYNAME]
##### Importing into tensorflow
#df['labels'] = df['ASSET NAME'].astype(float)
dataset = tf.data.Dataset.from_tensor_slices((xygrgb , labels))
print(dataset)
` 这是一个数据样本
如您所见,第二列和最后一列是字符串,其他是浮点值。我想输入这种类型的数据作为输入数据集。非常感谢任何帮助。
编辑*** 对于以下代码
dtypes = {'ASSEMBLY_NAME': np.int64, 'ASSETID': 'float'}
df = pd.read_csv("C:\TRAININGDATA\DATABASE.csv",dtype = dtypes)
print(df.dtypes)
我收到TypeError: Cannot cast array data from dtype('O') to dtype('int64') according to the rule 'safe'的错误
对于下面的代码
df = pd.read_csv("C:\TRAININGDATA\DATABASE.csv")
df['ASSEMBLY_NAME'] = df['ASSEMBLY_NAME'].astype(float)
print(df.dtypes)
我收到ValueError: could not convert string to float: 'scene0002_00_vh_clean_2'的错误
以下代码
df = pd.read_csv("C:\TRAININGDATA\DATABASE.csv")
df['ASSEMBLY_NAME'] = df['ASSEMBLY_NAME'].astype('string')
print(df.dtypes)
它们被转换为字符串,但浮点值没有被转换为张量
ASSEMBLY_NAME string
AssetID string
Asset Name string
OffsetX float32
OffsetY float32
OffsetZ float32
Matrix a1 float32
Matrix b1 float32
Matrix c1 float32
Matrix a2 float32
Matrix b2 float32
Matrix c2 float32
Matrix a3 float32
Matrix b3 float32
Matrix c3 float32
KeyPARAM string
dtype: object
我收到了错误
ValueError: Dimensions 7 and 10 are not compatible
【问题讨论】:
标签: python pandas dataframe tensorflow