Beispiel #1
0
def avaiable_gpus(detect_time=3, cpu_ratio=0.5, mem_ratio=0.5):
    """
    get avaiable gpu device ids
    :param detect_time: seconds for detect
    :param use_ratio: ratio lower bound of cpu and mem usage
    :return: a list of avaiable gpu ids
    """
    assert type(detect_time) == int and cpu_ratio <= 1. and mem_ratio <= 1.
    # print('detecting valid gpus in %d seconds' % detect_time)

    # 1.使用正则表达式获取单GPU总内存(所有显卡相同的情况)
    total_mem = int(
        re.findall(r'([0-9]+)MiB \|',
                   os.popen('nvidia-smi -i 0').readlines()[8])[0])

    # 2.检测符合资源要求的GPU
    pids, pcpu, mem, gpu_id = gi.get_info()
    for i in range(detect_time - 1):
        time.sleep(1)
        pids, _pcpu, _mem, gpu_id = gi.get_info()
        _pcpu, _mem = np.asarray(_pcpu), np.asarray(_mem)
        pcpu = pcpu + _pcpu
        mem = mem + _mem
    pcpu, mem = np.asarray(pcpu) / detect_time, np.asarray(mem) / detect_time
    valid_gpus = np.argwhere((pcpu <= cpu_ratio * 100) & (
        mem <= mem_ratio * total_mem)).reshape(-1).tolist()
    valid_gpus = sorted(valid_gpus, key=lambda x: mem[x] * 100 + pcpu[x])

    # 3. 打印信息
    # info = ['GPU%d: %d%%-%.1fG' % (x[0], x[1], x[2] / 1024) for x in zip(valid_gpus, pcpu[valid_gpus], mem[valid_gpus])]
    # print('valid gpus: | '.join(info))
    return valid_gpus
Beispiel #2
0
 def __init__(self):
     self.op_system_name = os.name
     self.user_name = getpass.getuser()
     # self.total, self.used, self.free = shutil.disk_usage("/")
     simp_list = shutil.disk_usage("/")
     self.total = simp_list[0] // (2**30)
     self.used = simp_list[1] // (2**30)
     self.free = simp_list[2] // (2**30)
     self.Gpu_is_empty = GPUInfo.get_info()
     self.Gpu_info = GPUInfo.get_info()
     self.mem = psutil.virtual_memory()
     self.mem_total = self.mem.total
     self.Virtual_memory = self.mem_total / (1024**3)
Beispiel #3
0
def __main__():
    op_system_name = os.name
    op_user = getpass.getuser()
    print(op_user)
    if op_system_name == 'posix':
        print("This operating System is a Mac")
    if op_system_name == 'nt':
        print("this operating System is a Windows")
    if op_system_name == "java":
        print("this operating System is Java")
    total, used, free = shutil.disk_usage("/")
    print("Total Storage: %d GB" % (total // (2**30)))
    print("Used Storage: %d GB" % (used // (2**30)))
    print("Free Storage: %d GB" % (free // (2**30)))
    print("cpu percentage = {}\nVirtual Storage = {}".format(
        psutil.cpu_percent(), psutil.virtual_memory()))
    for each in psutil.virtual_memory():
        print(each)
    print('memory % used:', psutil.virtual_memory()[2])
    print(GPUInfo.check_empty())
    print(GPUInfo.get_info())
    print(GPUInfo.gpu_usage())
    mem = psutil.virtual_memory()
    print(mem.total)
    print("Ram = {}".format(mem.total / 1024.**3))
    op_check = OpSysChecker()
    print("-----------------\n{}".format(op_check.return_info()))
Beispiel #4
0
def get_pids():
    # Gets all PIDs on all GPUs as a dictionary
    # Each key is a GPU ID
    info = GPUInfo.get_info()

    pids = info[0]
    pids = {value[0]: key for key, value in pids.items()}
    return pids
Beispiel #5
0
    print("Please install GPU version of TF")

from model.YOLOv4 import YOLOv4
import numpy as np
import gc
from tqdm import tqdm
from gpuinfo import GPUInfo

x = 320
y = 320
inp = np.ones((4, x, y, 3), dtype=np.float64)
network = YOLOv4(side=x)
network.compile(loss="mse", optimizer="sgd", metrics="acc")

small, medium, large = network(inp)
print(GPUInfo.get_info())
print((x, y), " work and give :", small.shape, medium.shape, large.shape)
network.summary()
print(network.layers[-1].output_shape)

from dataset import Dataset
dataset = Dataset(4,
                  network.layers[-1].output_shape,
                  shape=network.layers[0].input_shape[1:3])
print("input shape is :", dataset.shape)

image_path = dataset.get_dir("test")
labels = dataset.get_label_data("test")

print(np.array(image_path).shape)
print(labels[0])