Skip to content

Conversation

@Twenkid
Copy link

@Twenkid Twenkid commented Oct 2, 2022

global: show_with_system_viewer = False

The end of visualize_progress:
else:
if show_with_system_viewer: img.show()
else:
display_image = numpy.array(img)
display_image = cv2.cvtColor(display_image,cv2.COLOR_RGB2BGR)
cv2.imshow("PROGRESS", display_image)

global:  show_with_system_viewer = False 

The end of visualize_progress:
	else:
		if show_with_system_viewer: img.show()
		else: 
			display_image = numpy.array(img)
			display_image = cv2.cvtColor(display_image,cv2.COLOR_RGB2BGR)
			cv2.imshow("PROGRESS", display_image)
@dobkeratops
Copy link
Owner

I tried this on the Mac (cut pasting your changes), can't seem to get it working - I'll keep trying. 'cv2' didn't install though, needed a differnt import, there might be another way to get the same convenience, I'll keep looking. opencv could be useful for me to bring in for other reasons, let me think about that.

I saw some things suggesting how to do this with matplotlib which I already have imported, but those didn't work either. its unfortunate that PIL's standard image show doesn't return some kind of handle already. I saw people suggest solutions like firing up an image viewer in a separate process , and kill that process, lmao. it would be nice to do this without a web server.

@Twenkid
Copy link
Author

Twenkid commented Oct 5, 2022 via email

@dobkeratops
Copy link
Owner

dobkeratops commented Oct 5, 2022

right I also had pygame in the back of my mind, funnily enough (I have actually used that briefly), and SDL2 bindings from python could work . indeed someone else has also suggested tkinter. I see it is possible to make some kind of background UI thread .
Supposedly 'tkinter' is already there as a dependency of 'PIL'

@Twenkid
Copy link
Author

Twenkid commented Oct 5, 2022

If you apply a GUI library, they spawn their threads and callbacks are defined on starting windows in order to deal with the interface. You can update them etc., they are running. For opencv just a delay has to be added after updating in order to allow the OS to redraw the windows, maybe some memory locking/unlocking, e.g. 1 ms, possibly less; if it is constantly updated in a loop with a very high speed it may stay gray.

@Twenkid
Copy link
Author

Twenkid commented Oct 5, 2022

This is how I used matplotlib with non-blocking display:

def generate_images(model, test_input, tar, show=True, name=None):  #name - file, extension etc.
  
  prediction = model(test_input, training=True)
  plt.figure(figsize=(9, 4))
  plt.ion() #? for interactive
  display_list = [test_input[0], tar[0], prediction[0]]
  title = ['Input Image', 'Ground Truth', 'Predicted Image']
  for i in range(3):
    plt.subplot(1, 3, i+1)
    plt.title(title[i])
    # Getting the pixel values in the [0, 1] range to plot.
    if show:
        plt.imshow(display_list[i] * 0.5 + 0.5)    
        plt.axis('off')      
    if name!=None: plt.savefig(name)

  plt.pause(0.001)
  plt.show(block = False)

@Twenkid
Copy link
Author

Twenkid commented Oct 5, 2022

The ion-function:

"Interactive ON":

https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.ion.html

Another example:

import matplotlib.pyplot as plt
import numpy as np

t = 0.66 #pause, sec.

#the function to turn on interactive mode
plt.ion()
 
#creating randomly generate collections/data
random_array = np.arange(-4, 5)
collection_1 = random_array ** 2
collection_2 = 10 / (random_array ** 2 + 1)
figure, axes = plt.subplots()
 
axes.plot(random_array, collection_1,
          'rx', random_array,
          collection_2, 'b+',
          linestyle='solid')
 
plt.pause(t)
axes.fill_between(random_array,
                  collection_1,
                  collection_2,
                  where=collection_2>collection_1,
                  interpolate=True,

                  color='green', alpha=0.3)
plt.pause(t)

lgnd = axes.legend(['collection-1',
                    'collection-2'],
                   loc='upper center',
                   shadow=True)
plt.pause(t)                   


lgnd.get_frame().set_facecolor('#ffb19a')

plt.pause(t)         

@dobkeratops
Copy link
Owner

dobkeratops commented Oct 5, 2022

maybe overkill but I found there something to launch a web browser from python. that lets me show it the same way from both places (testing development on the Mac, and running it seriously on the desktop PC)

I might leave it at that for the timebeing. its better than it was, i.e. it can show an updating image in one window now.

I actually quite like the idea of sdl2 in the long run for rendering annotation data.. although that might be better as a seperate tool aswell. keep this just working on an image directory, and everything else is "make an image directory.."

regarding tensor board.. I'll keep that in the back of my mind. I do like being able to write debug visualiser code directly myself. I must say it looks like a big library to navigate.

thanks for the additional suggestions on matplotlib too.. I might try that again at some point.

firing up a web browser to show an image is overkill, but 99% of people have a browser open anyway

@dobkeratops
Copy link
Owner

as there's so many options on this eventually I think I need to make some kind of visualiser interface so it can be swapped out easily (use tensor board, whatever). for the timebeing I will stick with my adhoc 'render custom debug image' - I like being able to save that alongside the model . eventually. I'll make it show a grid of a few generated examples aswell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants