-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
867 changed files
with
59,066 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[run] | ||
omit = */test_*,*/test,*/test/*,build/*,src/customer/*,/private/*,/tmp/* | ||
|
||
[report] | ||
ignore_errors = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[flake8] | ||
ignore = E501,W503,E203,E266,E265,F811 | ||
# E501 line too long | ||
# W503 clang-formatter can produce line break before binary operator | ||
# E203 False positive "whitespaces before :" especially when slicing list, arrays etc. | ||
# E266 Too many leading '#' for block comment | ||
# E265 Block comment should start with '# ' | ||
# F811 A module has been imported twice, but seen when importing functions for fixtures in pytest files. | ||
exclude = **/*_pb2.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[settings] | ||
profile=black | ||
known_first_party=qai_hub_models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# exclude: | ||
# * third_party folders | ||
# * CloudFormation templates don't pass the yaml-check hook (a known issue) | ||
|
||
exclude: | | ||
(?x)( | ||
/build/ | ||
) | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.1.0 | ||
hooks: | ||
- id: check-yaml | ||
args: [--allow-multiple-documents] | ||
- id: trailing-whitespace | ||
exclude: '\.diff$' | ||
- id: check-added-large-files | ||
args: ['--maxkb=1024'] | ||
- id: check-merge-conflict | ||
- id: detect-aws-credentials | ||
args: [--allow-missing-credentials] | ||
- id: end-of-file-fixer | ||
exclude: | | ||
(?x)( | ||
\.diff$ | ||
) | ||
- id: fix-byte-order-marker | ||
- repo: https://github.com/rhysd/actionlint | ||
rev: v1.6.26 | ||
hooks: | ||
- id: actionlint | ||
- repo: https://github.com/shellcheck-py/shellcheck-py | ||
rev: v0.9.0.6 | ||
hooks: | ||
- id: shellcheck | ||
- repo: https://github.com/pycqa/isort | ||
rev: 5.12.0 | ||
hooks: | ||
- id: isort | ||
args: ["--filter-files"] | ||
- repo: https://github.com/psf/black | ||
rev: 22.1.0 | ||
hooks: | ||
- id: black | ||
additional_dependencies: ['click==8.0.4'] | ||
- repo: https://github.com/pycqa/flake8 | ||
rev: 6.1.0 | ||
hooks: | ||
- id: flake8 | ||
- repo: local | ||
hooks: | ||
- id: mypy | ||
name: mypy | ||
files: \.(py|pyi|ipynb|proto|fbs)$ | ||
entry: scripts/util/run_mypy.sh | ||
language: system |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
## How to update these rules | ||
## | ||
## From repo root, `pre-commit run -a shellcheck` to run shellcheck across all files in the repo. By default, the commit hook | ||
## will only run on your patch. However, CI runs it across all files, so if you're going to touch this file, I | ||
## recommend forcing it to run. | ||
## | ||
## To run on and fix a specific file, run: | ||
## shellcheck -x -f diff {filename} | apply | ||
## | ||
|
||
external-sources=true | ||
|
||
## Issue 7533: [shellcheck] Explore miscellaneous checks | ||
disable=SC2003 # expr is antiquated. Consider rewriting this using `$((..))`, `${}` or `[[ ]]`. | ||
disable=SC2005 # Useless `echo`? Instead of `echo $(cmd)`, just use `cmd` | ||
disable=SC2012 # Use `find` instead of `ls` to better handle non-alphanumeric filenames. | ||
disable=SC2116 # Useless echo? Instead of `cmd $(echo foo)`, just use `cmd foo`. | ||
disable=SC2155 # Declare and assign separately to avoid masking return values. | ||
disable=SC2166 # Prefer `[ p ] && [ q ]` as `[ p -a q ]` is not well defined. | ||
|
||
|
||
## things we probably don't care about ever fixing. | ||
|
||
disable=SC1083 # This `{`/`}` is literal. Check if `;` is missing or quote the expression. | ||
|
||
disable=SC2001 # See if you can use `${variable//search/replace}` instead. | ||
disable=SC2064 # Use single quotes, otherwise this expands now rather than when signalled. | ||
disable=SC2129 # Consider using `{ cmd1; cmd2; } >> file` instead of individual redirects. | ||
disable=SC2143 # Use `grep -q` instead of comparing output with `[ -n .. ]`. | ||
disable=SC2148 # Tips depend on target shell and yours is unknown. Add a shebang. | ||
disable=SC2162 # `read` without `-r` will mangle backslashes. | ||
disable=SC2164 # Use `cd ... || exit` in case `cd` fails. | ||
disable=SC2181 # Check exit code directly with e.g. `if mycmd;`, not indirectly with `$?`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Copyright 2024 Qualcomm® Technologies, Inc. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
[mypy] | ||
# https://mypy.readthedocs.io/en/stable/config_file.html#import-discovery | ||
exclude = "qai_hub_models/models" | ||
|
||
[mypy-huggingface_hub.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-onnx.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-onnxsim.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-onnxruntime.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-pytimeparse.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-skimage.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-setuptools.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-tensorflow.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-torchvision.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-transformers.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-tqdm.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-tap.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-h5py.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-flatbuffers.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-soundfile.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-datasets.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-keras.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-rangefilter.filters.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-schema.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-gdown.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-aimet_torch.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-boto3.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-botocore.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-ruamel.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-qai_hub_models.models.*] | ||
ignore_errors = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"exclude": [ | ||
"**/.mypy_cache", | ||
"**/.pytest_cache", | ||
"**/__pycache__", | ||
"**/node_modules", | ||
"build/tungsten", | ||
"src/public/staging_python/qai_hub_staging", | ||
"src/tungsten", | ||
"src/www/onnx-optimizer/third_party", | ||
"src/www/onnx-simplifier/third_party", | ||
], | ||
|
||
"extraPaths": [ | ||
"./build/proto" | ||
], | ||
|
||
"reportMissingModuleSource": "none", | ||
"reportMissingImports": true, | ||
"reportMissingTypeStubs": false, | ||
"reportShadowedImports": false, | ||
"verboseOutput": false, | ||
|
||
"venvPath": ".", | ||
"venv": "qaism-dev" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[pytest] | ||
testpaths = qai_hub_models | ||
norecursedirs = build | ||
python_files = tests.py test_*.py test.py | ||
filterwarnings = | ||
ignore::DeprecationWarning:coremltools.*: | ||
ignore::DeprecationWarning:torch.*: | ||
ignore::DeprecationWarning:torchvision.*: | ||
ignore::DeprecationWarning:tensorflow.*: | ||
ignore::DeprecationWarning:tensorflow-macos.*: | ||
ignore::DeprecationWarning:tensorflow-metal.*: | ||
ignore::DeprecationWarning:tensorflow-probability.*: | ||
markers = | ||
serial: test must not be run in parallel | ||
slow: marks tests as slow | ||
slow_cloud: marks test as slow and cloud-dependent |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "0.2.7" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
store_url: https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models | ||
web_asset_folder: models/{model_id}/web-assets | ||
static_web_banner_filename: banner.png | ||
animated_web_banner_filename: banner.mp4 | ||
model_asset_folder: models/{model_id}/v{version} | ||
dataset_asset_folder: datasets/{dataset_id}/v{version} | ||
repo_url: https://github.com/quic/ai-hub-models/blob/main | ||
qaihm_repo: qai_hub_models/models/{model_id} | ||
example_use: qai_hub_models/models/{model_id}#example--usage | ||
huggingface_path: qualcomm/{model_name} | ||
models_website_url: https://aihub.qualcomm.com | ||
models_website_relative_path: models/{model_id} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def pytest_configure(config): | ||
config.addinivalue_line("markers", "compile: Run compile tests.") | ||
config.addinivalue_line("markers", "profile: Run profile tests.") | ||
config.addinivalue_line("markers", "inference: Run inference tests.") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
from typing import Tuple | ||
|
||
import numpy as np | ||
import torch | ||
from PIL import Image | ||
|
||
from qai_hub_models.datasets.common import BaseDataset | ||
from qai_hub_models.utils.asset_loaders import CachedWebDatasetAsset | ||
|
||
BSD300_URL = ( | ||
"https://www2.eecs.berkeley.edu/Research/Projects/CS/vision/bsds/BSDS300-images.tgz" | ||
) | ||
BSD300_FOLDER_NAME = "BSDS300" | ||
BSD300_VERSION = 1 | ||
BSD300_ASSET = CachedWebDatasetAsset( | ||
BSD300_URL, BSD300_FOLDER_NAME, BSD300_VERSION, "BSDS300.tgz" | ||
) | ||
DATASET_LENGTH = 200 | ||
|
||
|
||
class BSD300Dataset(BaseDataset): | ||
""" | ||
BSD300 published here: https://www2.eecs.berkeley.edu/Research/Projects/CS/vision/bsds/ | ||
""" | ||
|
||
def __init__(self, scaling_factor=4): | ||
self.bsd_path = BSD300_ASSET.path(extracted=True) | ||
self.images_path = os.path.join(self.bsd_path, "images/train") | ||
BaseDataset.__init__(self, self.bsd_path) | ||
self.scaling_factor = scaling_factor | ||
|
||
def _validate_data(self) -> bool: | ||
images_path = os.path.join(self.dataset_path, "images/train") | ||
|
||
# Check image path exists | ||
if not os.path.exists(images_path): | ||
return False | ||
|
||
# Ensure the correct number of images are there | ||
files = os.listdir(images_path) | ||
images = [f for f in files if ".jpg" in f] | ||
if len(images) != DATASET_LENGTH: | ||
return False | ||
|
||
return True | ||
|
||
def _prepare_data(self): | ||
# Rename images to be more friendly to enumeration | ||
directory = os.path.join(self.dataset_path, "images/train") | ||
files = os.listdir(directory) | ||
for i, filename in enumerate(files): | ||
if filename.endswith(".jpg"): | ||
# Open the image and convert it to png | ||
try: | ||
with Image.open(os.path.join(directory, filename)) as img: | ||
img.save(os.path.join(directory, f"img_{i + 1:03d}_HR.jpg")) | ||
# delete the old image | ||
os.remove(os.path.join(directory, filename)) | ||
except ValueError: | ||
print(f"File {filename} does not exist!") | ||
|
||
def __len__(self): | ||
return DATASET_LENGTH | ||
|
||
def __getitem__(self, item) -> Tuple[torch.Tensor, torch.Tensor]: | ||
# We use the super resolution GT-and-test image preparation from AIMET zoo: | ||
# https://github.com/quic/aimet-model-zoo/blob/d09d2b0404d10f71a7640a87e9d5e5257b028802/aimet_zoo_torch/quicksrnet/dataloader/utils.py#L51 | ||
|
||
img = np.asarray( | ||
Image.open(os.path.join(self.images_path, f"img_{item + 1:03d}_HR.jpg")) | ||
) | ||
height, width = img.shape[0:2] | ||
|
||
# If portrait, transpose to landscape so that all tensors are equal size | ||
if height > width: | ||
img = np.transpose(img, (1, 0, 2)) | ||
height, width = img.shape[0:2] | ||
|
||
# Take the largest possible center-crop of it such that its dimensions are perfectly divisible by the scaling factor | ||
x_remainder = width % ( | ||
2 * self.scaling_factor | ||
if self.scaling_factor == 1.5 | ||
else self.scaling_factor | ||
) | ||
y_remainder = height % ( | ||
2 * self.scaling_factor | ||
if self.scaling_factor == 1.5 | ||
else self.scaling_factor | ||
) | ||
left = int(x_remainder // 2) | ||
top = int(y_remainder // 2) | ||
right = int(left + (width - x_remainder)) | ||
bottom = int(top + (height - y_remainder)) | ||
hr_img = img[top:bottom, left:right] | ||
|
||
hr_height, hr_width = hr_img.shape[0:2] | ||
|
||
hr_img = np.array(hr_img, dtype="uint8") | ||
new_size = (int(width / self.scaling_factor), int(height / self.scaling_factor)) | ||
lr_img = np.asarray(Image.fromarray(hr_img).resize(new_size)) | ||
lr_img = np.clip(lr_img, 0.0, 255.0).astype(np.uint8) | ||
|
||
lr_height, lr_width = lr_img.shape[0:2] | ||
|
||
# Sanity check | ||
assert ( | ||
hr_width == lr_width * self.scaling_factor | ||
and hr_height == lr_height * self.scaling_factor | ||
) | ||
|
||
lr_img_tensor = torch.from_numpy(lr_img.transpose((2, 0, 1))).contiguous() | ||
lr_img_tensor = lr_img_tensor.to(dtype=torch.float32).div(255) | ||
|
||
hr_img_tensor = torch.from_numpy(hr_img.transpose((2, 0, 1))).contiguous() | ||
hr_img_tensor = hr_img_tensor.to(dtype=torch.float32).div(255) | ||
|
||
return lr_img_tensor, hr_img_tensor | ||
|
||
def _download_data(self) -> None: | ||
BSD300_ASSET.fetch(extract=True) | ||
self._prepare_data() |
Oops, something went wrong.