背景關系是通過讀取加速度、冷卻水溫度、轉速、油耗、制動力等值來確定摩托車部件的健康狀況……
輸入資料:
water_temperature rpm federeindrückung in mm Spritverbrauch/100km Bremsverz?gerung [m/s2] ... Lichtanlage Reifen Rahmen Bordelektronik Auspuffanlage
0 99.995 6000 150 5.0 2 ... 99.995 99.995 99.995 99.995 99.995
1 80.000 11500 150 5.0 2 ... 99.995 99.995 99.995 99.995 99.995
2 80.000 6000 0 5.0 2 ... 99.995 99.000 99.000 99.995 99.000
3 80.000 6000 150 10.0 2 ... 99.995 99.995 99.995 99.995 99.995
4 80.000 8000 150 6.0 2 ... 99.995 99.995 99.995 99.995 99.995
5 75.000 8000 150 4.9 2 ... 99.995 99.995 99.995 99.995 99.995
6 75.000 8000 150 4.9 8 ... 99.995 99.000 99.000 99.995 99.995
7 80.000 8000 150 5.5 2 ... 99.995 99.995 99.995 99.995 99.995
8 83.000 8000 150 5.0 2 ... 99.995 99.995 99.995 99.995 99.995
9 79.000 8000 150 5.0 2 ... 99.000 99.995 99.000 98.000 99.000
10 80.000 11000 150 5.0 2 ... 99.995 99.995 99.995 99.995 99.995
神經網路的預測應該是1分鐘后摩托車各部分的剩余健康度,比如11500轉一分鐘,發動機損失1%的健康度。
所需的輸出資料:
Motor Federung Getriebe Bremsen Lichtanlage Reifen Rahmen Bordelektronik Auspuffanlage
0 99.000 99.995 99.000 99.995 99.995 99.995 99.995 99.995 99.995
1 98.000 99.995 99.000 99.995 99.995 99.995 99.995 99.995 99.995
2 99.995 97.000 99.995 99.995 99.995 99.000 99.000 99.995 99.000
3 98.000 99.995 99.995 99.995 99.995 99.995 99.995 99.995 99.995
4 99.995 99.995 99.995 99.995 99.995 99.995 99.995 99.995 99.995
5 99.995 99.995 99.995 99.995 99.995 99.995 99.995 99.995 99.995
6 99.995 99.995 99.995 99.000 99.995 99.000 99.000 99.995 99.995
7 99.995 99.995 99.995 99.995 99.995 99.995 99.995 99.995 99.995
8 98.000 99.995 99.995 99.995 99.995 99.995 99.995 99.995 99.995
9 99.995 99.995 99.995 99.000 99.000 99.995 99.000 98.000 99.000
10 98.000 99.995 99.995 99.995 99.995 99.995 99.995 99.995 99.995
目標是將整個程序轉換為神經網路。
到目前為止,我有這個代碼:
import pandas as pd
import tensorflow as tf
from tensorflow.keras import layers
names = open("./training_data_header.txt", "r").read().split(",")
motorbike_train = pd.read_csv("training_data.csv", names=names)
motorbike_features = motorbike_train.copy()
outputs = pd.DataFrame()
for i in range(7, len(names)):
outputs = pd.concat([outputs, motorbike_train.pop(names[i])], axis=1)
motorbike_model = tf.keras.Sequential(
[layers.Dense(16), layers.Dense(9, activation="sigmoid")]
)
motorbike_model.compile(
loss=tf.keras.losses.MeanSquaredError(), optimizer=tf.optimizers.Adam()
)
motorbike_model.fit(motorbike_features, outputs, epochs=10)
# print(motorbike_features)
# print(outputs)
print(motorbike_model.predict(motorbike_features.loc[0]))
這會導致以下錯誤:
Traceback (most recent call last):
File "/Users/tobiaswimmer/Documents/Development/atos-ktm-hackathon/ai/create-model.py", line 26, in <module>
print(motorbike_model.predict(motorbike_features.loc[0]))
File "/usr/local/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/var/folders/1r/2f_4g23d3zx5lb8m2_s28qt00000gn/T/__autograph_generated_filekm9z4tos.py", line 15, in tf__predict_function
retval_ = ag__.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope)
ValueError: in user code:
File "/usr/local/lib/python3.9/site-packages/keras/engine/training.py", line 1845, in predict_function *
return step_function(self, iterator)
File "/usr/local/lib/python3.9/site-packages/keras/engine/training.py", line 1834, in step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/usr/local/lib/python3.9/site-packages/keras/engine/training.py", line 1823, in run_step **
outputs = model.predict_step(data)
File "/usr/local/lib/python3.9/site-packages/keras/engine/training.py", line 1791, in predict_step
return self(x, training=False)
File "/usr/local/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/usr/local/lib/python3.9/site-packages/keras/engine/input_spec.py", line 248, in assert_input_compatibility
raise ValueError(
ValueError: Exception encountered when calling layer "sequential" (type Sequential).
Input 0 of layer "dense" is incompatible with the layer: expected axis -1 of input shape to have value 16, but received input with shape (None, 1)
Call arguments received by layer "sequential" (type Sequential):
? inputs=tf.Tensor(shape=(None, 1), dtype=float32)
? training=False
? mask=None
uj5u.com熱心網友回復:
您需要將張量的第一個維度設定為 1,以獲得 (1,16) 的輸入形狀:
import numpy as np
print(motorbike_model.predict(np.expand_dims(motorbike_features.loc[0], axis=0)))
不能使用 sigmoid 作為神經網路的輸出,否則每個輸出值將介于 0 和 1 之間。
編輯:嘗試以下
motorbike_model = tf.keras.Sequential(
[layers.Conv2D(32,1,padding='same',activation='relu',input_shape=(1,16,1)),
layers.Conv2D(64,1,padding='same',activation='relu'),
layers.Flatten(),
layers.Dense(64, activation='relu'),
layers.Dense(9)])
motorbike_model.summary()
motorbike_model.compile(
loss=tf.keras.losses.MeanSquaredError(),
optimizer=tf.optimizers.Adam()
)
motorbike_model.fit((np.expand_dims(motorbike_features, axis= (0,3))), outputs, epochs=150)
print(motorbike_model.predict(np.expand_dims(motorbike_features.loc[0], axis=(0,1,3))))
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/479767.html
