我有一个像这样的python脚本:
import tensorflow as tf
from tensorflow import keras
import numpy as np
import pandas as pd
import argparse
from concurrent import futures
[data ETL processing]
#Model code
model = keras.Sequential()
input_layer = keras.layers.Dense(20, input_shape=[20], activation='tanh')
model.add(input_layer)
output_layer = keras.layers.Dense(1, activation='sigmoid')
model.add(output_layer)
gd = tf.train.GradientDescentOptimizer(0.01)
model.compile(optimizer=gd, loss='mse')
sess = tf.Session() #NEW LINE
training_y = dependent_variables #produced in the data ETL processing section above
training_x = independent_variable#produced in the data ETL processing section above
init_op = tf.initializers.global_variables()
sess.run(init_op)#NEW LINE
def model_fit():
model.fit(training_x, training_y, epochs=20, steps_per_epoch =20 )
return model
with futures.ThreadPoolExecutor() as executor:# Or use ProcessPoolExecutor
executor.map(model_fit())
我正确地使用了多重处理来运行model_fit函数吗?
在运行多线程库和将'model.fit'作为行本身运行之间,我看不到任何改进。