Python Forum
I'm trying to visualize neuron weights with PIL but getting a white image.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I'm trying to visualize neuron weights with PIL but getting a white image.
#1
from PIL import Image
import copy
import numpy as np
import pickle
#-------Sample--------------------------------------(THIS WORKS)
# value = "01101000011001010110110001101100011011111"

# print(len(value))

# cmap = {'0': (0,155,3,0),
#         '1': (0,0,0)}

# data = [cmap[letter] for letter in value]
# img = Image.new('RGB', (8, (len(value)//8)+1), "white")
# print(data)
# img.putdata(data)
# img.show() 

#-------Sample---------------------------------------


class para_viz:
    def __init__(self,layers):
        self.layers=copy.deepcopy(layers)
        self.map()
    
    def map(self):
        for i in range(len(self.layers)):
            self.layers[i]=self.layers[i]/np.max(np.absolute(self.layers[i]),axis=0)
            self.layers[i]=self.layers[i]*255   
    
    def color_map(self,data):
        Data=[]
        for i in data:
            i=int(i)
            color=(i,0,0) if i>=0 else (0,i,0)
            Data.append(color)
        return Data

    def viz_neuron(self):
        neuron=self.layers[0][:,0]
        # print(neuron)
        flat_len=len(neuron)
        size=(flat_len//2,flat_len//2) if flat_len%2==0 else (flat_len//2,(flat_len//2)+1)
        img=Image.new('RGB',size,"white")
        data=self.color_map(neuron)
        print(len(data))
        img.putdata(data)
        img.show()


with open("weights.pkl","rb") as f:
    weights=pickle.load(f)

viz=para_viz(weights)
viz.viz_neuron()
weights.pkl---->https://drive.google.com/file/d/1ayDFQCigFQqe5vWdaR0QyMWh8OxYRmNc/view?usp=sharing
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] White edge sdgdfgg 4 845 Dec-14-2023, 04:48 AM
Last Post: reneejenkins
  What should I do the character comes to the door the background changes in to white. Killdoz 0 1,363 May-22-2020, 02:41 PM
Last Post: Killdoz
  Visual Studio 2019 and Neuron JamesBrown 0 1,839 Apr-06-2019, 05:12 PM
Last Post: JamesBrown
  Deleting White from Bitmap Anysja 8 5,587 Aug-14-2018, 04:04 PM
Last Post: Anysja
  [WxPython] How to create a static white box text giu88 2 2,548 Aug-14-2018, 10:50 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020