我有三個不同的傳感器。對于每個我根據 tf 有以下形狀:
sensor1.shape = (1134, 100, 400)
sensor2.shape = (1134, 100, 400)
sensor3.shape = (1134, 100, 400)
每個張量具有相同的大小。
在下一步中,我將這 3 個傳感器堆疊起來,以獲得只有 3 個維度的傳感器:
final = tf.stack([sensor1, sensor2, sensor3], axis=-1)
final.shape
TensorShape([1134, 100, 400, 3])
現在我想做一個火車測驗拆分
X_train, X_test, y_train, y_test = train_test_split(final, y, test_size=0.25, random_state=42, stratify=y)
但出現以下錯誤:
只有整數、切片 ( :)、省略號 ( ...)、 tf.newaxis ( None) 和標量 tf.int32/tf.int64 張量是有效索引,得到 array([ 219, 928, 636, 862, 606, 793 , 621, 118, 1047, 635, .. 有
什么想法嗎?怎么了?
編輯:只有1 個傳感器的當前作業解決方案。所以我認為問題是三個 3 維度。
sensor1.shape
(100, 400, 1134)
final = np.moveaxis(sensor1, -1, 0)
final.shape
(1134, 100, 400)
X_train, X_test, y_train, y_test = train_test_split(final, y, test_size=0.25, random_state=42, stratify=y)
print("X:", final.shape)
print("y:", y.shape)
print("Xtrain:", X_train.shape)
print("y_train:", y_train.shape)
print("X_test:", X_test.shape)
print("y_test:", y_test.shape)
X: (1134, 100, 400)
y: (1134,)
Xtrain: (850, 100, 400)
y_train: (850,)
X_test: (284, 100, 400)
y_test: (284,)
X_train = tf.expand_dims(X_train, axis=-1)
X_test = tf.expand_dims(X_test, axis=-1)
print("X_train shape new:", X_train.shape)
X_train shape new: (850, 100, 400, 1)
uj5u.com熱心網友回復:
嘗試使用numpy和train_test_split為一切:
import tensorflow as tf
import numpy as np
from sklearn.model_selection import train_test_split
sensor1 = np.random.random((1134, 100, 400))
sensor2 = np.random.random((1134, 100, 400))
sensor3 = np.random.random((1134, 100, 400))
Y = np.random.random((1134))
final = np.stack([sensor1, sensor2, sensor3], axis=-1)
X_train, X_test, y_train, y_test = train_test_split(final, Y, test_size=0.25, random_state=42)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/323902.html
