Skip to content

Commit

Permalink
Merge pull request #17 from naotoo1/feature/workflows-update
Browse files Browse the repository at this point in the history
Feature/workflows update
  • Loading branch information
naotoo1 authored Feb 15, 2024
2 parents f163963 + 672bfb0 commit b2c738f
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 7 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
on:
push:
branches:
- main
pull_request:
branches:
- main

name: macOS build
jobs:
test-macOS:
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} (${{ matrix.python-version}})
strategy:
fail-fast: false
matrix:
os: ["macOS-latest"]
python-version: ["3.10","3.11"]
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
lfs: true
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version}}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install --user -r requirements_dev.txt
- name: Test with pytest
run: |
python -m unittest discover test/
python -m pytest test/
- name: Train example
run: |
python train.py --data_name cifar10 --model iglvq --train_norm lpips-l2 --test_norm l1 --feature_extraction --prune --prune_mode easy --prune_fraction 0.8

43 changes: 43 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
on:
push:
branches:
- main
pull_request:
branches:
- main

name: Linux build
jobs:
py-check:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.py }})
strategy:
fail-fast: false
matrix:
config:
- { os: ubuntu-latest, py: "3.10" }
- { os: ubuntu-latest, py: "3.11" }
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
lfs: true
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.config.py }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --user -r requirements.txt
pip install --user -r requirements_dev.txt
- name: Module-TEST
run: |
python -m unittest discover test/
python -m pytest test/
- name: Train example
run: |
python train.py --data_name cifar10 --model iglvq --train_norm lpips-l2 --test_norm l1 --feature_extraction --prune --prune_mode easy --prune_fraction 0.8

44 changes: 44 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
on:
push:
branches:
- main
pull_request:
branches:
- main

name: Windows build

jobs:
test-windows:
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} (${{ matrix.python-version}})
strategy:
fail-fast: false
matrix:
os: ["windows-latest"]
python-version: ["3.10","3.11"]
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
lfs: true
- name: Install miniconda
uses: conda-incubator/setup-miniconda@v2
with:
auto-activate-base: true
python-version: ${{ matrix.python-version}}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install --user -r requirements_dev.txt
- name: Test with pytest
run: |
python -m unittest discover test/
python -m pytest test/
- name: Train example
run: |
python train.py --data_name cifar10 --model iglvq --train_norm lpips-l2 --test_norm l1 --feature_extraction --prune --prune_mode easy --prune_fraction 0.8

4 changes: 2 additions & 2 deletions evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_lowerbound_certification(
condition1 = q_norm in ["lpips-linf", "lpips-l2", "lpips-l1"]
match condition1:
case True:
device = "cuda"
device ="cuda" if torch.cuda.is_available() else "cpu"
case False:
device = "cpu"

Expand Down Expand Up @@ -105,7 +105,7 @@ def get_upperbound_certification(
condition1 = q_norm in ["lpips-linf", "lpips-l2", "lpips-l1"]
match condition1:
case True:
device = "cuda"
device ="cuda" if torch.cuda.is_available() else "cpu"
case False:
device = "cpu"

Expand Down
2 changes: 2 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
autopep8==2.0.2
pytest==7.0.1
8 changes: 6 additions & 2 deletions test/test_perceptual_metric.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Test Suite for Perceptual metric"""

import torch
from distance import lpips_distance
from train_utils import get_data, Dataset

Expand All @@ -9,7 +9,11 @@
test_size=0.3,
)
x_test = access_data.X_test
x_test = x_test.to("cuda")
if torch.cuda.is_available():
x_test = x_test.to("cuda")
else:
x_test = x_test.to(torch.device("cpu"))
# x_test = x_test.to("cuda")


input_0 = x_test[0].reshape(1, 32, 32, 3)
Expand Down
18 changes: 15 additions & 3 deletions test/test_psi_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@

# get image data
access_data = get_data(dataset="cifar10", test_size=0.3)
x_test = access_data.X_test.to("cuda")
if torch.cuda.is_available():
x_test = access_data.X_test.to("cuda")
else:
x_test = access_data.X_test.to(torch.device("cpu"))
# x_test = access_data.X_test.to("cuda")

# reshape the input
input_0 = x_test[0].reshape(1, 32, 32, 3)
Expand All @@ -34,9 +38,17 @@ def test_normalization_factor_1(self):
torch.sqrt(torch.sum(feature_layer**2, dim=1, keepdim=True))
+ self.epsilon
)
self.assertIsInstance(
if torch.cuda.is_available():
self.assertIsInstance(
normalization_factor_1[0][0][0][0], torch.cuda.FloatTensor
)
)
else:
self.assertIsInstance(
normalization_factor_1[0][0][0][0], torch.FloatTensor
)
# self.assertIsInstance(
# normalization_factor_1[0][0][0][0], torch.cuda.FloatTensor
# )
self.assertEqual(torch.sum(normalization_factor_1, dim=0).any(), 1)

def test_normalization_factor_2(self):
Expand Down

0 comments on commit b2c738f

Please sign in to comment.