Estaba intentando hacer un script de TensorFlow. Este script que intentaba hacer se basa principalmente en extraer el valor de una o más variables con respecto al tiempo, ir comparando y mostrar 2 gráficas finales. Una que diga qué valores ha logrado almacenar la red neuronal y otra que muestre una curva de los posibles valores que tomará en un futuro cercano (Pueden ser 20, 30, 50, etc.). Este es el script que llevo (Por el momento):
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tensorflow/1.7.2/tf.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"> </script>
</head>
<body>
x:<input type="number" id="x">
y:<input type="number" id="y">
<input type="button" id="append" value="submit">
<div style="padding:50px">
<canvas id="prevChart"style="display:inline-block"></canvas>
<canvas id="postChart"style="display:inline-block"></canvas>
</div>
<script>
xs=[]
ys=[]
fxs=[]
fys=[]
document.getElementById('x').value=0
document.getElementById('y').value=0
prevCTX=document.getElementById("prevChart").getContext('2d')
postCTX=document.getElementById("postChart").getContext('2d')
document.getElementById('append').onclick=()=>{
x=document.getElementById('x').value
y=document.getElementById('y').value
xs.push(eval(x))
ys.push(eval(y))
document.getElementById('x').value=parseInt(x)+1
//Create the predictor:
model=tf.sequential()
model.add(tf.layers.dense({units:5,inputShape:[5,5]}))
model.compile({loss:'meanSquaredError',optimizer:'sgd'})
//Train the predictor:
model.fit(tf.stack(xs), ys, {epochs: 1})
// Chart original data:
new Chart(prevCTX, {
type: 'line',
options: {scales:{yAxes: [{ticks: {beginAtZero: true}}]}},
data: {
labels: xs,
datasets: [{
label: 'Original Data',
data: ys,
borderWidth: 1,
borderColor: "gray"
}]
},
});
// Chart estimated data:
new Chart(postCTX, {
type: 'line',
options: {scales:{yAxes: [{ticks: {beginAtZero: true}}]}},
data: {
labels: fxs,
datasets: [{
label: 'Predicted Data',
data: fys,
borderWidth: 1,
borderColor: "gray"
}]
},
});
}
</script>
</body>
Pero al intentar ejecutarlo me salió un error:
Uncaught (in promise) Error: Error when checking input: expected dense_Dense6_input to have 3 dimension(s). but got array with shape 6,1
at new t (errors.ts:48)
at standardizeInputData (training.ts:156)
at t.standardizeUserDataXY (training.ts:1161)
at t.<anonymous> (training.ts:1188)
at common.ts:14
at Object.next (common.ts:14)
at common.ts:14
at new Promise (<anonymous>)
at __awaiter (common.ts:14)
at t.standardizeUserData (training.ts:1185)
He probado a cambiar los inputs, a hacer todo lo que dicen las preguntas... y nada... Quisiera saber una solución efectiva de este error y como finalmente poder meter datos en el model
y poder ejecutar mi script con éxito. ¿Alguien tiene la solución a mi problema?