cysmith / neural-style-tf

TensorFlow (Python API) implementation of Neural Style
GNU General Public License v3.0
3.11k stars 828 forks source link

How can i get the value of loss fun when use lbfgs method #61

Open pep-pig opened 6 years ago

pep-pig commented 6 years ago

i want to plot the convergence curves of different solve method ,but i can not get the value of loss function when use lbfgs,it only print value in cmd . i need save it into a list,how can i do that?

chamoulox commented 6 years ago

Hello,

I'm actually doing this too, Have you find something ?

I'm doing some tests so it's NOT good code:

As a beginning, i have created a global array (LOSS_TOTAL) and I have set a callback function in minimize_with_lbfgs function optimizer.minimize(sess,loss_callback=save_loss,fetches=[L_total])

and save loss is defined as follow:

def save_loss(loss):
LOSS_TOTAL.append(loss)

in order to plot, i have added some lines after the display of elapsing time in render_signe_image function:

print('Single image elapsed time: {}'.format(tock - tick))
plt.plot(LOSS_TOTAL)
plt.savefig('fig.jpg')

So now i'm able to see my loss function evolution, except it's not very useful as starting loss value is way higher than loss value after some iterations

My final goal if to stop computing if loss function reaches asymptotic value.

pep-pig commented 6 years ago

I add some code in lbfgs.py located in scipy\optimize , so i can plot the curve during the computing process. here is my project

cysmith commented 6 years ago

@vonlippmann Nice. Do you know why this happens?

pep-pig commented 6 years ago

i am sorry , i don't how this happen too.