In the name of God
This gist contains steps to setup Ubuntu 22.04 for deep learning.
| # mainly from: | |
| # 1. https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#env-vars | |
| # 2. https://github.com/NVIDIA/DeepLearningExamples/issues/57 | |
| # 3. https://docs.nvidia.com/deeplearning/frameworks/tensorflow-user-guide/index.html#variablesaddtf | |
| def is_using_hvd(): | |
| env_vars = ["OMPI_COMM_WORLD_RANK", "OMPI_COMM_WORLD_SIZE"] | |
| if all([var in os.environ for var in env_vars]): | |
| return True |
| from __future__ import print_function | |
| import argparse | |
| import torch.backends.cudnn as cudnn | |
| import torch.nn.functional as F | |
| import torch.optim as optim | |
| import torch.utils.data.distributed | |
| from torchvision import models | |
| import horovod.torch as hvd | |
| import timeit |
| import torch | |
| import torchvision | |
| class VGGPerceptualLoss(torch.nn.Module): | |
| def __init__(self, resize=True): | |
| super(VGGPerceptualLoss, self).__init__() | |
| blocks = [] | |
| blocks.append(torchvision.models.vgg16(pretrained=True).features[:4].eval()) | |
| blocks.append(torchvision.models.vgg16(pretrained=True).features[4:9].eval()) | |
| blocks.append(torchvision.models.vgg16(pretrained=True).features[9:16].eval()) |
| import os | |
| import torch | |
| import argparse | |
| from maskrcnn_benchmark.config import cfg | |
| from maskrcnn_benchmark.utils.c2_model_loading import load_c2_format | |
| def removekey(d, listofkeys): | |
| r = dict(d) | |
| for key in listofkeys: |
| # if input image is in range 0..1, please first multiply img by 255 | |
| # assume image is ndarray of shape [height, width, channels] where channels can be 1, 3 or 4 | |
| def imshow(img): | |
| import cv2 | |
| import IPython | |
| _,ret = cv2.imencode('.jpg', img) | |
| i = IPython.display.Image(data=ret) | |
| IPython.display.display(i) |
| import cv2 | |
| import time | |
| person_cascade = cv2.CascadeClassifier( | |
| os.path.join('/path/to/haarcascade_fullbody.xml')) | |
| cap = cv2.VideoCapture("/path/to/test/video") | |
| while True: | |
| r, frame = cap.read() | |
| if r: | |
| start_time = time.time() |
| """ | |
| author: Timothy C. Arlen | |
| date: 28 Feb 2018 | |
| Calculate Mean Average Precision (mAP) for a set of bounding boxes corresponding to specific | |
| image Ids. Usage: | |
| > python calculate_mean_ap.py | |
| Will display a plot of precision vs recall curves at 10 distinct IoU thresholds as well as output |