Update quality tooling for formatting (#21480)
* Result of black 23.1 * Update target to Python 3.7 * Switch flake8 to ruff * Configure isort * Configure isort * Apply isort with line limit * Put the right black version * adapt black in check copies * Fix copies
This commit is contained in:
@@ -9,9 +9,9 @@ from collections import OrderedDict
|
||||
import datasets
|
||||
import numpy as np
|
||||
import torch
|
||||
|
||||
from modeling_frcnn import GeneralizedRCNN
|
||||
from processing_image import Preprocess
|
||||
|
||||
from utils import Config
|
||||
|
||||
|
||||
|
||||
@@ -169,7 +169,6 @@ def get_norm(norm, out_channels):
|
||||
|
||||
|
||||
def _create_grid_offsets(size: List[int], stride: int, offset: float, device):
|
||||
|
||||
grid_height, grid_width = size
|
||||
shifts_x = torch.arange(
|
||||
offset * stride,
|
||||
@@ -390,7 +389,6 @@ def assign_boxes_to_levels(
|
||||
canonical_box_size: int,
|
||||
canonical_level: int,
|
||||
):
|
||||
|
||||
box_sizes = torch.sqrt(torch.cat([boxes.area() for boxes in box_lists]))
|
||||
# Eqn.(1) in FPN paper
|
||||
level_assignments = torch.floor(canonical_level + torch.log2(box_sizes / canonical_box_size + 1e-8))
|
||||
@@ -1708,9 +1706,10 @@ class GeneralizedRCNN(nn.Module):
|
||||
elif os.path.isfile(pretrained_model_name_or_path) or is_remote_url(pretrained_model_name_or_path):
|
||||
archive_file = pretrained_model_name_or_path
|
||||
elif os.path.isfile(pretrained_model_name_or_path + ".index"):
|
||||
assert from_tf, (
|
||||
"We found a TensorFlow checkpoint at {}, please set from_tf to True to load from this checkpoint"
|
||||
.format(pretrained_model_name_or_path + ".index")
|
||||
assert (
|
||||
from_tf
|
||||
), "We found a TensorFlow checkpoint at {}, please set from_tf to True to load from this checkpoint".format(
|
||||
pretrained_model_name_or_path + ".index"
|
||||
)
|
||||
archive_file = pretrained_model_name_or_path + ".index"
|
||||
else:
|
||||
|
||||
@@ -34,14 +34,13 @@ from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
from zipfile import ZipFile, is_zipfile
|
||||
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
from tqdm.auto import tqdm
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
import requests
|
||||
import wget
|
||||
from filelock import FileLock
|
||||
from PIL import Image
|
||||
from tqdm.auto import tqdm
|
||||
from yaml import Loader, dump, load
|
||||
|
||||
|
||||
@@ -181,7 +180,6 @@ class Config:
|
||||
|
||||
@classmethod
|
||||
def get_config_dict(cls, pretrained_model_name_or_path: str, **kwargs):
|
||||
|
||||
cache_dir = kwargs.pop("cache_dir", None)
|
||||
force_download = kwargs.pop("force_download", False)
|
||||
resume_download = kwargs.pop("resume_download", False)
|
||||
@@ -225,14 +223,13 @@ class Config:
|
||||
|
||||
# quick compare tensors
|
||||
def compare(in_tensor):
|
||||
|
||||
out_tensor = torch.load("dump.pt", map_location=in_tensor.device)
|
||||
n1 = in_tensor.numpy()
|
||||
n2 = out_tensor.numpy()[0]
|
||||
print(n1.shape, n1[0, 0, :5])
|
||||
print(n2.shape, n2[0, 0, :5])
|
||||
assert np.allclose(n1, n2, rtol=0.01, atol=0.1), (
|
||||
f"{sum([1 for x in np.isclose(n1, n2, rtol=0.01, atol=0.1).flatten() if x == False])/len(n1.flatten())*100:.4f} %"
|
||||
f"{sum([1 for x in np.isclose(n1, n2, rtol=0.01, atol=0.1).flatten() if x is False])/len(n1.flatten())*100:.4f} %"
|
||||
" element-wise mismatch"
|
||||
)
|
||||
raise Exception("tensors are all good")
|
||||
@@ -300,7 +297,6 @@ def get_from_cache(
|
||||
user_agent=None,
|
||||
local_files_only=False,
|
||||
):
|
||||
|
||||
if cache_dir is None:
|
||||
cache_dir = TRANSFORMERS_CACHE
|
||||
if isinstance(cache_dir, Path):
|
||||
@@ -355,7 +351,6 @@ def get_from_cache(
|
||||
# Prevent parallel downloads of the same file with a lock.
|
||||
lock_path = cache_path + ".lock"
|
||||
with FileLock(lock_path):
|
||||
|
||||
# If the download just completed while the lock was activated.
|
||||
if os.path.exists(cache_path) and not force_download:
|
||||
# Even if returning early like here, the lock will be released.
|
||||
@@ -406,7 +401,6 @@ def get_from_cache(
|
||||
|
||||
|
||||
def url_to_filename(url, etag=None):
|
||||
|
||||
url_bytes = url.encode("utf-8")
|
||||
url_hash = sha256(url_bytes)
|
||||
filename = url_hash.hexdigest()
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
import colorsys
|
||||
import io
|
||||
|
||||
import cv2
|
||||
import matplotlib as mpl
|
||||
import matplotlib.colors as mplc
|
||||
import matplotlib.figure as mplfigure
|
||||
@@ -25,7 +26,6 @@ import numpy as np
|
||||
import torch
|
||||
from matplotlib.backends.backend_agg import FigureCanvasAgg
|
||||
|
||||
import cv2
|
||||
from utils import img_tensorize
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user