gaussian-splatting icon indicating copy to clipboard operation
gaussian-splatting copied to clipboard

add GPU number and lazy load img to GPU

Open sword4869 opened this issue 2 years ago • 4 comments
trafficstars

hello,

  1. I add a gpu number argument in ModelParams class.
  2. In order to save GPU memory, I cancelled the loading of img to GPU when creating the camera, and delayed loading img to GPU during training. This greatly saves GPU memory. I tested it in RTX2080ti and less than 2GB during initial training, even if trained to 30k, less than 5GB.

sword4869 avatar Nov 07 '23 14:11 sword4869

This is a great improvement in memory usage, this should be merged into main branch. @Snosixtyboo

pablospe avatar Nov 23 '23 15:11 pablospe

typo, should be device with a c --data_device cpu

NiklasVoigt avatar Dec 11 '23 09:12 NiklasVoigt

typo, should be device with a c --data_device cpu

tks for ur careful check

sword4869 avatar Dec 13 '23 02:12 sword4869

maybe we can reduce more usage of memory by lazy call function loadCam.

def lazy_call(f, *args, **kwargs):
    return lambda: f(*args, **kwargs)

def cameraList_from_camInfos(cam_infos, resolution_scale, args, lazy_load):
    camera_list = []
    # pdb.set_trace()
    for id, c in enumerate(cam_infos):
        if lazy_load:
            camera_list.append(lazy_call(loadCam, args, id, c, resolution_scale))
        else:
            camera_list.append(loadCam(args, id, c, resolution_scale))
    return camera_list`

In function 'cameraList_from_camInfos', we can delay executing loadCam and execute it in 'training'.

# Pick a random Camera
if not viewpoint_stack:
    viewpoint_stack = scene.getTrainCameras().copy()
viewpoint_cam = viewpoint_stack.pop(randint(0, len(viewpoint_stack)-1))
if scene.lazy_load:
    viewpoint_cam = viewpoint_cam()

Ky1eYang avatar Jul 23 '24 05:07 Ky1eYang