This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function, absolute_import | |
__all__ = ['accuracy'] | |
def accuracy(output, target, topk=(1,)): | |
"""Computes the precision@k for the specified values of k""" | |
maxk = max(topk) | |
batch_size = target.size(0) | |
_, pred = output.topk(maxk, 1, True, True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OctConv(nn.Module): | |
def __init__(self, ch_in, ch_out, kernel_size, stride=1, alphas=[0.5,0.5]): | |
super(OctConv, self).__init__() | |
# Get layer parameters | |
self.alpha_in, self.alpha_out = alphas | |
assert 0 <= self.alpha_in <= 1 and 0 <= self.alpha_in <= 1, \ | |
"Alphas must be in interval [0, 1]" | |
self.kernel_size = kernel_size | |
self.stride = stride |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# EDIT 10/04/2022 - This version was provided by @jayelm who fixed some bugs and made the function much more robust | |
import os | |
import subprocess | |
import time | |
def assign_free_gpus(threshold_vram_usage=1500, max_gpus=2, wait=False, sleep_time=10): | |
""" | |
Assigns free gpus to the current process via the CUDA_AVAILABLE_DEVICES env variable | |
This function should be called after all imports, |