我需要帮助解决以下问题。我正在尝试将我的 csv 数据提供给我的第一层是 convolution1d 但它显示
输入 0 与层 conv1d_Conv1D1 不兼容:预期 ndim=3,发现 ndim=2
这是我的代码
//move the tfjs_binding.node file in build-tmp-napi-v7/Release folder to build-tmp-napi-v7 folder will solve the problem.
const dfd = require("danfojs-node");
const tf = require("@tensorflow/tfjs-node");
var petData;
const TIME_STEPS = (24 * 60) / 60;
console.log("start");
var model = tf.sequential();
model.add(
tf.layers.conv1d({
filters: 3,
kernelSize: 3,
inputShape:[1]
})
);
// model.add(tf.layers.dropout({ rate: 0.2 }));
// model.add(
// tf.layers.conv1d({
// filters: 16,
// kernelSize: 7,
// padding: "same",
// strides: 2,
// activation: "relu",
// })
// );
// model.add(
// tf.layers.conv1d({
// filters: 16,
// kernelSize: 7,
// padding: "same",
// strides: 2,
// activation: "relu",
// })
// );
// model.add(tf.layers.dropout({ rate: 0.2 }));
// model.add(
// tf.layers.conv1d({
// filters: 32,
// kernelSize: 7,
// padding: "same",
// strides: 2,
// activation: "relu",
// })
// );
// model.add(
// tf.layers.conv1d({
// filters: 1,
// kernelSize: 7,
// padding: "same",
// })
// );
model.compile({
optimizer: tf.train.adam((learningRate = 0.001)),
loss: tf.losses.meanSquaredError,
});
model.summary();
console.log("model created.");
dfd
.read_csv("./petTempData.csv", (chunk = 10000))
.then((df) => {
let encoder = new dfd.LabelEncoder();
let cols = ["Date", "Time"];
cols.forEach((col) => {
encoder.fit(df[col]);
enc_val = encoder.transform(df[col]);
df.addColumn({ column: col, value: enc_val });
});
petData = df.iloc({ columns: [`1`] });
yData = df["Temperature"];
// let scaler = new dfd.MinMaxScaler();
// scaler.fit(petData);
// petData = scaler.transform(petData);
// petData = petData.tensor.expandDims(-1);
// const data = petData.tensor.reshape([24, 2, 1]);
console.log(petData.shape);
model.fit(petData.tensor, yData.tensor, {
epochs: 10,
batchSize: 4,
// validationSplit: 0.01,
callbacks: tf.callbacks.earlyStopping({
monitor: "loss",
patience: "5",
mode: "min",
}),
});
})
.catch((err) => {
console.log(err);
});
这是我的 csv 原始文件
Date,Time,Temperature
31-12-2020,01:30,36.6
31-12-2020,02:30,36.7
31-12-2020,03:30,36.6
31-12-2020,04:30,36.5
31-12-2020,05:30,36.8
31-12-2020,06:30,36.6
31-12-2020,07:30,36.6
31-12-2020,08:30,36.5
31-12-2020,09:30,36.6
31-12-2020,10:30,36.7
31-12-2020,11:30,36.6
31-12-2020,12:30,36.7
31-12-2020,13:30,36.7
31-12-2020,14:30,36.8
31-12-2020,15:30,36.9
31-12-2020,16:30,36.6
31-12-2020,17:30,36.7
31-12-2020,18:30,36.8
31-12-2020,19:30,36.7
31-12-2020,20:30,36.6
31-12-2020,21:30,36.6
31-12-2020,22:30,36.5
31-12-2020,23:30,36.5
,,
我试图重塑我的输入,并 expandDims 但它们都不起作用。非常感谢任何解决方案!