Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to visualize pytorch model filters

    import numpy as np
    import matplotlib.pyplot as plt
    from torchvision import utils

    def visTensor(tensor, ch=0, allkernels=False, nrow=8, padding=1): 
        n,c,w,h = tensor.shape

        if allkernels: tensor = tensor.view(n*c, -1, w, h)
        elif c != 3: tensor = tensor[:,ch,:,:].unsqueeze(dim=1)

        rows = np.min((tensor.shape[0] // nrow + 1, 64))    
        grid = utils.make_grid(tensor, nrow=nrow, normalize=True, padding=padding)
        plt.figure( figsize=(nrow,rows) )
        plt.imshow(grid.numpy().transpose((1, 2, 0)))


    if __name__ == "__main__":
        layer = 1
        filter = model.features[layer].weight.data.clone()
        visTensor(filter, ch=0, allkernels=False)

        plt.axis('off')
        plt.ioff()
        plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: the webpage at http://127.0.0.1:8000/ might be temporarily down or it may have moved permanently to a new web address. django 
Python :: UTC to ISO 8601 with Local TimeZone information without microsecond (Python 3): 
Python :: How do I select certain columns for regression plots 
Python :: how to run function when file is modified python 
Python :: iterate 
Python :: python sys replace text 
Python :: python clean filename 
Python :: le %s 
Python :: python program to convert csv file into pdf 
Python :: # swap variables 
Python :: # generators 
Python :: # sort the dictionary 
Python :: Linear Search Python with enumerate 
Python :: how delet an obj from memori in python 
Python :: pop tkinter to the front of the screen 
Python :: extracting bounding box from xml file python 
Python :: Find Factors of a Number using While Loop with validation 
Python :: add Elements to Python list Using extend() method 
Python :: pyqt global hotkey 
Python :: keyword argument python 
Python :: 0xff in python 
Python :: CHECK POLYGON IS VALID 
Python :: find a paragraph in requests-html 
Python :: Python NumPy ravel function example array.ravel is equivalent to reshape(-1, order=order) 
Python :: python dictionary examples 
Python :: Python NumPy hstack Function Example with 2d array 
Python :: fpdf latin-1 
Python :: Python __le__ magic method 
Python :: godot knockback 
Python :: drop column 0 to many 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =