-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess.py
52 lines (45 loc) · 1.14 KB
/
preprocess.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
import tensorflow as tf
import numpy as np
def excersice(workout):
if workout=='less':
w=[1,0,0]
elif workout=='med':
w=[0,1,0]
elif workout=='high':
w=[0,0,1]
return w
def sex(gender):
if gender=='m':
g=[1,0]
elif gender=='f':
g=[0,1]
return g
def cal(calorie):
if calorie<=2000:
c=[1,0,0]
elif calorie<=2500:
c=[0,1,0]
elif calorie>2500:
c=[0,0,1]
return c
def preprocessing(workout,bmi,gender,calorie):
w=np.array(excersice(workout),dtype='float32')
g=np.array(sex(gender),dtype='float32')
w_b=np.append(w,[bmi],axis=0)
w_b_g=np.append(w_b,g,axis=0)
c=np.array(cal(calorie))
return np.array([np.append(w_b_g,c,axis=0)],dtype='float32')
def output(array):
r=np.array(np.reshape(array,(6,)),dtype='int')
j=1
for i in r:
if i==0:
j=j+1
return j
model=tf.keras.models.load_model("recc_diet.h5")
"""
Example:-
Input in preprocessing (workout,bmi,gender,calorie)
ans=output(model.predict(preprocessing('less',25,'m',3000)))
"""
ans=output(model.predict(preprocessing('less',25,'m',3000)))