Spaces:
Build error
Build error
Nahuel
commited on
Commit
•
da152c5
1
Parent(s):
201f85f
initial commit
Browse files- app.py +47 -0
- data/FD001_x_test.npy +0 -0
- data/FD001_y_train.npy +0 -0
- data/FD001_z_train.npy +0 -0
- data/FD002_x_test.npy +0 -0
- data/FD002_y_train.npy +0 -0
- data/FD002_z_train.npy +0 -0
- data/FD003_x_test.npy +0 -0
- data/FD003_y_train.npy +0 -0
- data/FD003_z_train.npy +0 -0
- data/FD004_x_test.npy +0 -0
- data/FD004_y_train.npy +0 -0
- data/FD004_z_train.npy +0 -0
- models/FD001.h5 +3 -0
- models/FD002.h5 +3 -0
- models/FD003.h5 +3 -0
- models/FD004.h5 +3 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import gradio as gr
|
3 |
+
from tensorflow.keras.models import load_model
|
4 |
+
import matplotlib
|
5 |
+
matplotlib.use('Agg')
|
6 |
+
from matplotlib import pyplot as plt
|
7 |
+
|
8 |
+
def get_model(path):
|
9 |
+
saved_VRAE_model = load_model(path, compile=False)
|
10 |
+
|
11 |
+
# return encoder, regressor
|
12 |
+
return saved_VRAE_model.layers[1], saved_VRAE_model.layers[2]
|
13 |
+
|
14 |
+
def predict(subset, engine):
|
15 |
+
# ------------------------ Prediction ------------------------
|
16 |
+
path = './models/'+subset+'.h5'
|
17 |
+
y_train = np.load('./data/'+subset+'_y_train.npy', allow_pickle=True)
|
18 |
+
x_test = np.load('./data/'+subset+'_x_test.npy', allow_pickle=True)
|
19 |
+
|
20 |
+
# Get model
|
21 |
+
encoder, regressor = get_model(path)
|
22 |
+
|
23 |
+
# latent space in train
|
24 |
+
fig = plt.figure()
|
25 |
+
z_train = np.load('./data/'+subset+'_z_train.npy', allow_pickle=True)
|
26 |
+
plt.scatter(z_train[:, 0], z_train[:, 1], c=y_train, cmap='RdYlGn')
|
27 |
+
clb = plt.colorbar()
|
28 |
+
clb.set_label('RUL', labelpad=-30, y=1.05, rotation=0)
|
29 |
+
z, _, _ = encoder.predict(x_test[engine].reshape(1, x_test[engine].shape[0], x_test[engine].shape[1]))
|
30 |
+
plt.scatter(z[:, 0], z[:, 1], c='red', marker='x')
|
31 |
+
plt.xlabel('z - dim 1')
|
32 |
+
plt.ylabel('z - dim 2')
|
33 |
+
|
34 |
+
pred = regressor.predict(z)[0][0]
|
35 |
+
|
36 |
+
return int(pred), fig
|
37 |
+
|
38 |
+
iface = gr.Interface(
|
39 |
+
fn=predict,
|
40 |
+
inputs=[gr.inputs.Radio(["FD001", "FD002", "FD003", "FD004"]), gr.inputs.Slider(1, 100, step=1)],
|
41 |
+
title="RUL Estimation for CMAPSS dataset",
|
42 |
+
description="Enter subset and engine number to predict the remaining useful life (RUL)",
|
43 |
+
outputs=[gr.outputs.Label(label="Prediction"), gr.outputs.Plot(type="auto", label="Latent space")],
|
44 |
+
allow_screenshot=False,
|
45 |
+
theme="dark-peach",
|
46 |
+
layout="unaligned")
|
47 |
+
iface.launch()
|
data/FD001_x_test.npy
ADDED
Binary file (60.1 kB). View file
|
|
data/FD001_y_train.npy
ADDED
Binary file (57.1 kB). View file
|
|
data/FD001_z_train.npy
ADDED
Binary file (114 kB). View file
|
|
data/FD002_x_test.npy
ADDED
Binary file (187 kB). View file
|
|
data/FD002_y_train.npy
ADDED
Binary file (150 kB). View file
|
|
data/FD002_z_train.npy
ADDED
Binary file (300 kB). View file
|
|
data/FD003_x_test.npy
ADDED
Binary file (60.1 kB). View file
|
|
data/FD003_y_train.npy
ADDED
Binary file (70.9 kB). View file
|
|
data/FD003_z_train.npy
ADDED
Binary file (142 kB). View file
|
|
data/FD004_x_test.npy
ADDED
Binary file (179 kB). View file
|
|
data/FD004_y_train.npy
ADDED
Binary file (174 kB). View file
|
|
data/FD004_z_train.npy
ADDED
Binary file (348 kB). View file
|
|
models/FD001.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:87f54016db2e69f8d2a9f7139ac84fccc764154fc529ace46a6102bef72577f6
|
3 |
+
size 8895936
|
models/FD002.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:25ec05897c9be6a923e3ac037cd0f7db86a3cf474079fc87ab55ef1fbb744d68
|
3 |
+
size 8947560
|
models/FD003.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:df3feefdfed1efd7e7203a370113775c47b48d71ecabdb31b0ec504aecad7718
|
3 |
+
size 8918760
|
models/FD004.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:93d16ed766a9450d7ea300726ae2431da9f9ee9435ca143a26e335978fcb2917
|
3 |
+
size 8947560
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow==2.3.0
|
2 |
+
matplotlib==3.3.4
|
3 |
+
pandas==1.1.5
|