-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from BloodAxe/feature/modules-overhaul
Feature/modules overhaul
- Loading branch information
Showing
27 changed files
with
626 additions
and
101 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
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,66 @@ | ||
name: "CodeQL" | ||
|
||
on: | ||
push: | ||
branches: [ 'master' ] | ||
pull_request: | ||
# The branches below must be a subset of the branches above | ||
branches: [ 'master' ] | ||
schedule: | ||
- cron: '39 12 * * 5' | ||
|
||
jobs: | ||
analyze: | ||
name: Analyze | ||
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} | ||
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} | ||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
language: [ 'python' ] | ||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] | ||
# Use only 'java' to analyze code written in Java, Kotlin or both | ||
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both | ||
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
# Initializes the CodeQL tools for scanning. | ||
- name: Initialize CodeQL | ||
uses: github/codeql-action/init@v2 | ||
with: | ||
languages: ${{ matrix.language }} | ||
# If you wish to specify custom queries, you can do so here or in a config file. | ||
# By default, queries listed here will override any specified in a config file. | ||
# Prefix the list here with "+" to use these queries and those in the config file. | ||
|
||
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs | ||
# queries: security-extended,security-and-quality | ||
|
||
|
||
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). | ||
# If this step fails, then you should remove it and run the build manually (see below) | ||
- name: Autobuild | ||
uses: github/codeql-action/autobuild@v2 | ||
|
||
# ℹ️ Command-line programs to run using the OS shell. | ||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun | ||
|
||
# If the Autobuild fails above, remove it and uncomment the following three lines. | ||
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. | ||
|
||
# - run: | | ||
# echo "Run, Build Application using script" | ||
# ./location_of_script_within_repo/buildscript.sh | ||
|
||
- name: Perform CodeQL Analysis | ||
uses: github/codeql-action/analyze@v2 | ||
with: | ||
category: "/language:${{matrix.language}}" |
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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
from .inria_aerial import * | ||
from .coco_detection import * |
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,112 @@ | ||
import dataclasses | ||
import json | ||
import os.path | ||
from collections import defaultdict | ||
from typing import List | ||
|
||
import numpy as np | ||
from torch.utils.data import Dataset | ||
|
||
__all__ = ["DetectionSample", "COCODetectionDatasetReader"] | ||
|
||
|
||
@dataclasses.dataclass | ||
class DetectionSample: | ||
image_id: str | ||
image_path: str | ||
image_width: int | ||
image_height: int | ||
|
||
labels: np.ndarray # [N] | ||
bboxes: np.ndarray # [N, 4] in XYXY format | ||
is_difficult: np.ndarray # [N] | ||
|
||
|
||
class COCODetectionDatasetReader(Dataset): | ||
samples: List[DetectionSample] | ||
class_names: List[str] | ||
num_classes: int | ||
|
||
def __init__(self, samples: List[DetectionSample], class_names: List[str]): | ||
self.samples = samples | ||
self.class_names = class_names | ||
self.num_classes = len(class_names) | ||
|
||
def __getitem__(self, item): | ||
return self.samples[item] | ||
|
||
def __len__(self): | ||
return len(self.samples) | ||
|
||
@staticmethod | ||
def convert_to_dict(annotations): | ||
result_dict = defaultdict(list) | ||
for obj in annotations: | ||
image_id = obj["image_id"] | ||
result_dict[image_id].append(obj) | ||
return result_dict | ||
|
||
@classmethod | ||
def from_directory_and_annotation(cls, images_directory: str, annotation: str): | ||
samples = [] | ||
with open(annotation, "r") as f: | ||
data = json.load(f) | ||
|
||
category_ids, class_names = zip(*[(category["id"], category["name"]) for category in data["categories"]]) | ||
|
||
annotations = cls.convert_to_dict(data["annotations"]) | ||
category_id_to_index = {category_id: index for index, category_id in enumerate(category_ids)} | ||
|
||
for image in data["images"]: | ||
image_id = image["id"] | ||
image_path = os.path.join(images_directory, image["file_name"]) | ||
image_width = image["width"] | ||
image_height = image["height"] | ||
|
||
labels = [] | ||
bboxes = [] | ||
is_difficult = [] | ||
|
||
if image_id in annotations: | ||
for annotations in annotations[image_id]: | ||
class_index = category_id_to_index[annotations["category_id"]] | ||
x, y, w, h = annotations["bbox"] | ||
bbox_xyxy = [x, y, x + w, y + h] | ||
|
||
labels.append(class_index) | ||
bboxes.append(bbox_xyxy) | ||
is_difficult.append(annotations["iscrowd"]) | ||
|
||
sample = DetectionSample( | ||
image_id=image_id, | ||
image_path=image_path, | ||
image_width=image_width, | ||
image_height=image_height, | ||
labels=np.array(labels, dtype=int).reshape(-1), | ||
bboxes=np.array(bboxes, dtype=np.float32).reshape(-1, 4), | ||
is_difficult=np.array(is_difficult, dtype=bool).reshape(-1), | ||
) | ||
samples.append(sample) | ||
|
||
return cls(samples, class_names) | ||
|
||
|
||
if __name__ == "__main__": | ||
import cv2 | ||
|
||
start = cv2.getTickCount() | ||
train_ds = COCODetectionDatasetReader.from_directory_and_annotation( | ||
images_directory="e:/coco2017/images/train2017/", annotation="e:/coco2017/annotations/instances_train2017.json" | ||
) | ||
end = cv2.getTickCount() | ||
print((end - start) / cv2.getTickFrequency()) | ||
|
||
start = cv2.getTickCount() | ||
valid_ds = COCODetectionDatasetReader.from_directory_and_annotation( | ||
images_directory="e:/coco2017/images/val2017/", annotation="e:/coco2017/annotations/instances_val2017.json" | ||
) | ||
end = cv2.getTickCount() | ||
print((end - start) / cv2.getTickFrequency()) | ||
|
||
print(len(train_ds)) | ||
print(len(valid_ds)) |
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
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
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
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
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
Oops, something went wrong.