Overview of my code: in python, I trained a GAN model to generate an image, given a vector of 8 numerical values (8 numbers ranging from -1 to 1). Let's call such a vector "noise". So, this CGAN model takes noise as input and then generates an image. If I want to generate 100 images, then the noise input would be an array of 100 vectors (each with 8 numerical values ranging from -1 to 1). See example below.
noise = np.random.rand(100,8) #generating array of 100 vectors w/ 8 numerical values each
noise = 2.0*noise - 1
gen_imgs = gen_mdl.predict(noise) #images generated with trained GAN model
Then, after I generate these images, I also want to assign them a "performance" value. This is where matlab comes into play. So, in matlab, I trained a kriging model to take each image's "noise" vector as input (the 8 numerical values) and then output a performance value (a value ranging from 0 to 700). The problem is that for 100 images, it takes about 2 minutes to generate the performance values for each. And, I think this latency is due to the matlab-python connection. So, I'm wondering if there's a different way that I can connect matlab & python in order to speed up the generation of the 100 performance values.
This is the python function that calls the matlab model (that generates performance values). Note: the "comp_vals" or "comp_scores" are the performance values.
def gen_comp_vals(noise):
sio.savemat('latent_vars.mat', {'latent_vars':noise})
eng = matlab.engine.start_matlab()
eng.Kriging_to_python(nargout=0)
eng.quit()
comp_vals=sio.loadmat('comp_vals.mat')
comp_scores=comp_vals['comp_vals'][0]
return comp_scores
And, this is the matlab file "Kriging_to_python" that the python function above is calling:
%Load matlab workspace with kriging model
krig_workspace=load('C:\Users\User\Documents\MATLAB\krig_posttrain_workspace2.mat');
%Import latent variable values from python
latent_from_python=load('/Users/User/Documents/Framework/latent_vars.mat');
latent_vars=latent_from_python.latent_vars;
latent_vars=single(latent_vars);
%Save kriging model from workspace as new variable
krig_model=krig_workspace.dmodel;
%Run kriging model with latent variables generated from python
[comp_vals MSEpredict] = predictor(latent_vars, krig_model);
comp_vals=transpose(comp_vals);
save('/Users/User/Documents/Framework/comp_vals.mat','comp_vals');
From what's shown above, do you see a change I can make to speed up the generation of these performance values? Possibly a different way to connect matlab & python?
Thanks!