Skip to content
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

Set opencv as optional #286

Merged
merged 1 commit into from
Jan 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions yolort/utils/image_utils.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
from pathlib import Path
from typing import Optional

import cv2
import matplotlib.pyplot as plt
import numpy as np
import requests
@@ -13,6 +12,11 @@
from torch import Tensor
from torchvision.ops.boxes import box_convert

try:
import cv2
except ImportError:
cv2 = None

logger = logging.getLogger(__name__)


@@ -80,10 +84,7 @@ def hex2rgb(h):
return [hex2rgb(h) for h in plt.rcParams["axes.prop_cycle"].by_key()["color"]]


def get_image_from_url(
url: str,
flags: int = cv2.IMREAD_COLOR,
) -> np.ndarray:
def get_image_from_url(url: str, flags: int = 1) -> np.ndarray:
"""
Generates an image directly from an URL
6 changes: 5 additions & 1 deletion yolort/v5/utils/augmentations.py
Original file line number Diff line number Diff line change
@@ -7,9 +7,13 @@
import math
import random

import cv2
import numpy as np

try:
import cv2
except ImportError:
cv2 = None

from .general import colorstr, segment2box, resample_segments, check_version
from .metrics import bbox_ioa

9 changes: 7 additions & 2 deletions yolort/v5/utils/general.py
Original file line number Diff line number Diff line change
@@ -16,14 +16,18 @@
import urllib
from pathlib import Path

import cv2
import numpy as np
import pandas as pd
import pkg_resources as pkg
import torch
import torchvision
import yaml

try:
import cv2
except ImportError:
cv2 = None

from .metrics import box_iou, fitness

# Settings
@@ -32,7 +36,8 @@
np.set_printoptions(linewidth=320, formatter={"float_kind": "{:11.5g}".format})
pd.options.display.max_columns = 10
# prevent OpenCV from multithreading (incompatible with PyTorch DataLoader)
cv2.setNumThreads(0)
if cv2 is not None:
cv2.setNumThreads(0)
os.environ["NUMEXPR_MAX_THREADS"] = str(min(os.cpu_count(), 8)) # NumExpr max threads

FILE = Path(__file__).resolve()
6 changes: 5 additions & 1 deletion yolort/v5/utils/plots.py
Original file line number Diff line number Diff line change
@@ -8,14 +8,18 @@
from copy import copy
from pathlib import Path

import cv2
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import torch
from PIL import Image, ImageDraw, ImageFont

try:
import cv2
except ImportError:
cv2 = None

from .general import (
LOGGER,
Timeout,