-
Notifications
You must be signed in to change notification settings - Fork 13.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to use gpu limit #970
Comments
The problem is related to the high dimension of the image. A simple and basic approach, can be resize the photo. It will simply resize the photo. You can tweak for you purpouse. def load_image_file(file, mode='RGB',):
"""
Loads an image file (.jpg, .png, etc) into a numpy array
:param file: image file name or file object to load
:param mode: format to convert the image to. Only 'RGB' (8-bit RGB, 3 channels) and 'L' (black and white) are supported.
:return: image contents as numpy array
"""
im = PIL.Image.open(file)
width, height = im.size
w, h = width, height
log = logging.getLogger()
ratio = -1
# Ratio for resize the image
log.debug("load_image_file | Image dimension: ({}:{})".format(w, h))
# Resize in case of to bigger dimension
if 1200 <= width <= 1600 or 1200 <= height <= 1600:
ratio = 1/2
elif 1600 <= width <= 3600 or 1600 <= height <= 3600:
ratio = 1/3
elif width > 3600 or height > 3600:
if width > height:
ratio = width/800
else:
ratio = height/800
log.debug("Dimension: w: {} | h: {}".format(w, h))
log.debug("new ratio -> {}".format(ratio))
if 0 < ratio < 1:
# Scale image in case of width > 1600
w = width * ratio
h = height * ratio
elif ratio > 1:
# Scale image in case of width > 3600
w = width / ratio
h = height / ratio
if w != width:
# Check if scaling was applied
maxsize = (w, h)
log.debug(
"Image have to high dimension, avoiding memory error. Resizing to {}".format(maxsize))
im.thumbnail(maxsize, PIL.Image.ANTIALIAS)
if mode:
im = im.convert(mode)
return np.array(im), ratio |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello
i use face_recognition and i have some question
can i limit gpu usage??
The text was updated successfully, but these errors were encountered: