Machine learning 无法为我的卷积1D提供csv数据

Machine learning 无法为我的卷积1D提供csv数据,machine-learning,conv-neural-network,convolution,tensorflow.js,danfojs,Machine Learning,Conv Neural Network,Convolution,Tensorflow.js,Danfojs,我需要帮助解决以下问题。 我试图将我的csv数据输入到我的第一层,这是卷积1D,但它显示 输入0与层conv1d\U 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("danfoj

我需要帮助解决以下问题。 我试图将我的csv数据输入到我的第一层,这是卷积1D,但它显示

输入0与层conv1d\U 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
,,
我尝试重新设置输入,并扩展DIM,但都不起作用。
非常感谢任何解决方案

conv1d层需要一个dim 2的inputShape,因此,inputShape需要是
[a,b]
(带a,b正整数)


您好,我已经按照您所说的做了,但是问题仍然是一样的,
b
应该大于内核大小(如果内核大小是一个数字);如果内核大小是一个数组
[c,d]
,那么
a>c
b>d
我也尝试过了,但是它仍然产生了相同的结果。如果您进行了建议的更改,则不会产生相同的错误。请看我在回答中添加的示例,不客气。如果答案有帮助,别忘了投票并将其标记为已接受:)
model = tf.sequential();
model.add(
  tf.layers.conv1d({
    filters: 3,
    kernelSize: 1,
    inputShape:[1, 3]
  })
);

model.predict(tf.ones([1, 1, 3])).print()