-
Notifications
You must be signed in to change notification settings - Fork 0
/
diagnosis.py
60 lines (49 loc) · 1.78 KB
/
diagnosis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from .model import *
from .preprocessing import *
import numpy as np
class Diagnosis:
"""
Fault Diagnosis Class
"""
def __init__(self) -> None:
self.model = TCN_LSTM(
output_size=4, num_channels=[40] * 8, kernel_size=6, dropout=0.05
)
self.model.build(input_shape=([1, 800]))
self.model.load_weights("./checkpoints/tcn_lstm.h5")
def diagnosis(self, data_path):
"""
Motor fault diagnosis based on pretrained MCNN-LSTM
Args:
motor (int): motor number which gonna diagnose status
Returns:
status (str): result of deep learning diagnosis
"""
# get current data
data = get_data(data_path)
# get diagnosis result
y_pre = self.model(data, training=False)
y_pre = np.array(y_pre, dtype=np.float32).reshape(y_pre.shape[0], 4)
label_pre = np.argmax(y_pre, axis=1)
predicted = [
len(np.where(label_pre == 0)[0]),
len(np.where(label_pre == 1)[0]),
len(np.where(label_pre == 2)[0]),
len(np.where(label_pre == 3)[0]),
]
print("[WARN] Predicted rate(N-M-U-B):", predicted)
result = predicted.index(max(predicted))
if max(predicted) < len(label_pre) // 2 + 5:
return "Normal"
if result == 0:
return "Normal"
elif result == 1:
return "Misalignment"
elif result == 2:
return "Unbalance"
elif result == 3:
return "Damaged Bearing"
if __name__ == "__main__":
tcn_lstm = Diagnosis()
current_data_dir = input("Enter path of current vibration data directory: ")
result = tcn_lstm.diagnosis(current_data_dir)