Tensorflow.js (Node.js 사용) 를 사용하여 Celsius를 Fahrenheit로 변환하는 모델을 만들고 싶습니다 .
그러나 어떤 모양 을 사용 해야하는지 이해가 안됩니다 .
나는 다른 시도 input_shape
와 같은 [1]
, [1,20]
그리고에 마지막으로 설정 [20]
나는 또한 같은 섭씨 및 화씨 배열에 대해 서로 다른 텐서 형태를 시도했다 tensor(celsius)
, tensor([celsius])
.
다음은 코드입니다.
var model = tf.sequential()
model.add(tf.layers.dense({inputShape:[20], units: 1}))
async function trainModel(model, inputs, labels) {
// Prepare the model for training.
model.compile({
optimizer: tf.train.adam(),
loss: tf.losses.meanSquaredError,
metrics: ['mse'],
});
const batchSize = 28;
const epochs = 500;
return await model.fit(inputs, labels, {
epochs,
shuffle: true,
// callbacks: tfvis.show.fitCallbacks(
// { name: 'Training Performance' },
// ['loss', 'mse'],
// { height: 200, callbacks: ['onEpochEnd'] }
// )
});
}
c = tf.tensor([celsius]) // celsius = [1,2,3,4,...]
console.log(c.shape) // ==> [1,20]
f = tf.tensor([fahrenheit])
console.log(f.shape) // ==> [1,20]
trainModel(model, c, f)
또한 Python 자습서 input_shape
에서는 [1]
. Node.js에서는 [20]
작동하는 것 같습니다.
입력의 모양 [1,20]
이 정확하고 정확합니다.
레이블 모양 [1,20]
도 좋지만 다음 오류가 발생합니다.
디버거 말한다 :
Error when checking target: expected dense_Dense1 to have shape [,1], but got array with shape [1,20].
- 편집하다
또한 시도 input_shape: [1,20]
하면 다음과 같은 결과가 나타납니다.
expected dense_Dense1_input to have 3 dimension(s). but got array with shape 1,20
-
모델이 C ° 값을 F ° 값에 연결하여 학습시킬 것으로 예상합니다.
감사합니다
오류는 분명합니다.
{inputShape:[20], units: 1}
모델은 단일 레이어를 포함합니다. inputShape:[20]
이는 [null, 20]
첫 번째 레이어의 모양이 될 batchInputShape를 의미 합니다. 마찬가지로 units: 1
는 마지막 레이어의 모양이임을 나타냅니다 [null, 1]
.
사용 된 기능은 모델의 batchInputShape와 일치하는 모양 [1, 20]을 갖습니다. 그러나 모양이있는 레이블은 그렇지 않습니다 [1, 20]
. [1, 1]
따라서 모양이 있어야 오류가 발생합니다.
density_Dense1이 [, 1] 모양을 가질 것으로 예상했지만 [1,20] 모양의 배열이 있습니다.
모델의 단위 크기는 라벨 모양을 반영하도록 변경되어야합니다.
{inputShape:[20], units: 20}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다