Python 将预先训练好的tensorflow回归模型集成到spring boot后端
我使用GoogleColab创建了一个模型,我想将它集成到我用SpringBoot(后端)和react(前端)编写的项目中。我只想从前端传递参数Python 将预先训练好的tensorflow回归模型集成到spring boot后端,python,spring-boot,tensorflow,machine-learning,Python,Spring Boot,Tensorflow,Machine Learning,我使用GoogleColab创建了一个模型,我想将它集成到我用SpringBoot(后端)和react(前端)编写的项目中。我只想从前端传递参数 import numpy as np import tensorflow.compat.v1 as tf tf.disable_v2_behavior() import pandas as pd import matplotlib.pyplot as plt D = pd.read_csv("nat64_2_merge.csv")
import numpy as np
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
import pandas as pd
import matplotlib.pyplot as plt
D = pd.read_csv("nat64_2_merge.csv")
x_data = np.matrix(D.Time.values)
y_data = np.matrix(D.Length.values)
plt.plot(x_data.T, y_data.T, 'x') # The 'x' means that data points will be marked with an x
plt.xlabel('Time')
plt.ylabel('Length')
plt.title('Relationship between Time and Length')
plt.show()
x = tf.placeholder(tf.float32, shape=(1, None))
a = tf.get_variable("a", shape=())
b = tf.get_variable("b", shape=())
y_predicted = a*x + b
y = tf.placeholder(tf.float32, shape=(1, None))
L = tf.reduce_sum((y_predicted - y)**2)
optimizer = tf.train.AdamOptimizer(learning_rate=0.2).minimize(L)
session = tf.Session()
session.run(tf.global_variables_initializer())
for t in range(10000):
_, current_loss, current_a, current_b = session.run([optimizer, L, a, b], feed_dict={
x: x_data,
y: y_data
})
print("t = %g, loss = %g, a = %g, b = %g" % (t, current_loss, current_a, current_b))
x_test_data = np.matrix(np.linspace(0, 600)) //here I add parameters then create prediction line
y_test_data = session.run(y_predicted, feed_dict={
x: x_test_data
})
plt.plot(x_data.T, y_data.T, 'x')
plt.plot(x_test_data.T, y_test_data.T)
plt.xlabel('Time')
plt.ylabel('Length')
plt.title('Time and Length linear regression')
plt.show()
在最后一行中,我想将该绘图放到前端,并将其显示给最终用户
提前谢谢