GeorgyVlasov commited on
Commit
63c2d15
·
1 Parent(s): e03c65f

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -149
app.py DELETED
@@ -1,149 +0,0 @@
1
-
2
- import gradio as gr
3
- import numpy as np
4
- import tensorflow as tf
5
- from tensorflow.keras.models import load_model
6
- from io import BytesIO
7
- import xml
8
- import untangle
9
- import mvnx
10
- from mvnx import MVNX
11
- import matplotlib
12
- import matplotlib.pyplot as plt
13
- import scipy.signal
14
- import copy
15
- import numpy as np
16
-
17
-
18
- model = load_model('model/my_model.keras')
19
-
20
-
21
-
22
-
23
- def classify_movement(file):
24
-
25
- labels = ['bench', 'squat']
26
-
27
- mvnx_file = file.name
28
-
29
- data = mvnx.MVNX(mvnx_file)
30
-
31
- position_data = data.get_info('position') # Change to the appropriate attribute
32
-
33
- position_tensor = np.array([list(frame.values()) for frame in position_data])
34
-
35
- # Get the dimensions of the position tensor
36
- num_frames, num_joints, num_features = position_tensor.shape
37
-
38
- # Determine the desired sequence length
39
- max_sequence_length = 1200 # Choose an appropriate value
40
-
41
- # Calculate the amount of padding needed
42
- padding_amount = max_sequence_length - num_frames
43
-
44
- # Create a tensor with zeros to represent padding
45
- padding_tensor = tf.zeros((padding_amount, num_joints, num_features))
46
-
47
- # Concatenate the padding tensor to the position tensor along the first axis
48
- padded_position_tensor = tf.concat([position_tensor, padding_tensor], axis=0)
49
-
50
- transformed_tensor = tf.expand_dims(padded_position_tensor, axis=0)
51
- # Predict
52
- pn = model.predict(transformed_tensor)
53
-
54
- prob_dict = {'bench':float(pn[0][0]), 'squat':float(pn[0][1])}
55
-
56
-
57
- return prob_dict
58
-
59
-
60
-
61
-
62
- import numpy as np
63
- import plotly.graph_objs as go
64
-
65
- def plot_3d_joint_trajectories(file):
66
-
67
- mvnx_file = file.name
68
-
69
- data = mvnx.MVNX(mvnx_file)
70
-
71
- position_data = data.get_info('position') # Change to the appropriate attribute
72
-
73
- sample = np.array([list(frame.values()) for frame in position_data])
74
-
75
- # Get the number of joints and timesteps
76
- num_joints = sample.shape[1]
77
- num_timesteps = sample.shape[0]
78
-
79
- # Create a list to store scatter plot traces
80
- traces = []
81
-
82
- # Iterate through all joints
83
- for joint_index in range(num_joints):
84
- # Extract the X, Y, and Z coordinates of the joint over all time steps
85
- x_coords = sample[:, joint_index, 0]
86
- y_coords = sample[:, joint_index, 1]
87
- z_coords = sample[:, joint_index, 2]
88
-
89
- # Create a scatter plot trace for the joint's movement trajectory
90
- trace = go.Scatter3d(
91
- x=x_coords,
92
- y=y_coords,
93
- z=z_coords,
94
- mode='lines',
95
- name=f'Joint {joint_index}'
96
- )
97
- traces.append(trace)
98
-
99
- # Create the figure
100
- fig = go.Figure(data=traces)
101
-
102
- # Set layout
103
- fig.update_layout(
104
- scene=dict(
105
- xaxis_title='X',
106
- yaxis_title='Y',
107
- zaxis_title='Z'
108
- ),
109
- title='Interactive 3D Movement Trajectories of All Joints'
110
- )
111
-
112
- # Show the interactive plot in a web browser
113
- return fig
114
-
115
-
116
-
117
-
118
- title="Movement Binary Classification with TensorFlow"
119
- description="Demo app for Movement type classification with TensorFlow using data from mvnx file. To use it, simply upload your mvnx file (should be less than 1200 datapoints) or click on one of the examples to load them."
120
-
121
- examples=['squat-test-30kg.mvnx', 'benchpress-test-35kg.mvnx']
122
-
123
-
124
-
125
-
126
- classifier = gr.Interface(fn = classify_movement,
127
- inputs=gr.File(),
128
- outputs=gr.Label(),
129
-
130
-
131
-
132
-
133
-
134
- )
135
-
136
- plotter = gr.Interface(fn=plot_3d_joint_trajectories,
137
- inputs=gr.File(),
138
- outputs=gr.Plot(),
139
-
140
-
141
- )
142
-
143
-
144
- demo = gr.Parallel(classifier, plotter, examples = examples, title=title, description = description)
145
-
146
-
147
- demo.launch()
148
-
149
-