opengenome.outputs#

Submodules#

Functions#

viz(→ None)

Display a visualization of CNN feature map

Package Contents#

opengenome.outputs.viz(layer_num: int, img_path: str, model: Any, classes: List[str | int | float], device: str) None#

Display a visualization of CNN feature map

Display convolutional neural network CNN feature maps of specified layer given image path and model.

Parameters:
  • layer_num (int) – Layer number of CNN to visualize.

  • img_path (str) – Path to input image.

  • model – PyTorch CNN model

  • device (str) – Device to run inference on exp. cuda:0 or cpu

Examples

>>> from opengenome.outputs.cnn import viz
>>> import torch
>>> from torchvision.models import vgg16, VGG16_Weights
>>> DEVICE = 'cuda:0' if torch.cuda.is_available() else 'cpu'
>>> with open("VGG16_CLASSES.txt", 'r') as f:
>>>    classes = f.readlines()
>>> model = vgg16(weights=VGG16_Weights.DEFAULT)
>>> model = model.to(DEVICE)
>>> img_car = r"PATH_TO_IMAGE"
>>> viz(10, img_car, model, classes, DEVICE)