Browse Source

[MNT] merge with branch main

tags/v0.3.2
Gene 2 years ago
parent
commit
6249a930f4
15 changed files with 155 additions and 14 deletions
  1. +54
    -0
      .github/workflows/install_learnware_with_pip.yaml
  2. +59
    -0
      .github/workflows/install_learnware_with_source.yaml
  3. +2
    -1
      learnware/client/learnware_client.py
  4. +1
    -2
      learnware/specification/__init__.py
  5. +2
    -5
      learnware/specification/base.py
  6. +2
    -0
      learnware/specification/regular/__init__.py
  7. +13
    -0
      learnware/specification/regular/base.py
  8. +0
    -0
      learnware/specification/regular/image/__init__.py
  9. +0
    -0
      learnware/specification/regular/image/cnn_gp.py
  10. +3
    -1
      learnware/specification/regular/image/rkme.py
  11. +0
    -0
      learnware/specification/regular/table/__init__.py
  12. +3
    -3
      learnware/specification/regular/table/rkme.py
  13. +0
    -0
      learnware/specification/system/__init__.py
  14. +15
    -0
      learnware/specification/system/heter_table.py
  15. +1
    -2
      learnware/specification/utils.py

+ 54
- 0
.github/workflows/install_learnware_with_pip.yaml View File

@@ -0,0 +1,54 @@
name: Test leanrnware from pip

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
timeout-minutes: 120

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-20.04, ubuntu-22.04, macos-11, macos-latest]
python-version: [3.8, 3.9, 3.10]

steps:
- name: Test learnware from pip
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
echo $CONDA/bin >> $GITHUB_PATH
- name: Create conda env for macos
run: |
conda create -n learnware python=${{ matrix.python-version }}
conda create activate learnware

- name: Update pip to the latest version
run: |
python -m pip install --upgrade pip
python -m pip install pytest

- name: Install faiss for MacOS
if: ${{ matrix.os == 'macos-11' || matrix.os == 'macos-latest' }}
run: |
conda install -c pytorch faiss

- name: Install learnware
run: |
python -m pip install learnware

- name: Test workflow
run: |
pytest tests/test_workflow/test_workflow.py

+ 59
- 0
.github/workflows/install_learnware_with_source.yaml View File

@@ -0,0 +1,59 @@
name: Test leanrnware from source code

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
timeout-minutes: 120

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-20.04, ubuntu-22.04, macos-11, macos-latest]
python-version: [3.8, 3.9, 3.10]

steps:
- name: Test learnware from pip
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
echo $CONDA/bin >> $GITHUB_PATH
- name: Create conda env for macos
run: |
conda create -n learnware python=${{ matrix.python-version }}
conda create activate learnware

- name: Update pip to the latest version
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics

- name: Install faiss for MacOS
if: ${{ matrix.os == 'macos-11' || matrix.os == 'macos-latest' }}
run: |
conda install -c pytorch faiss

- name: Install learnware
run: |
python -m pip install .

- name: Test workflow
run: |
pytest tests/test_workflow/test_workflow.py

+ 2
- 1
learnware/client/learnware_client.py View File

@@ -408,7 +408,8 @@ class LearnwareClient:
try:
for key in ["Data", "Task", "Library"]:
value = semantic_spec[key]["Values"]
if len(value) != 1 and value[0] not in key_list:
key_list = C["semantic_specs"][key]["Values"]
if len(value) != 1 or value[0] not in key_list:
logger.error(f"{key} must be in {key_list}!")
return False



+ 1
- 2
learnware/specification/__init__.py View File

@@ -1,4 +1,3 @@
from .utils import generate_stat_spec, generate_rkme_spec, generate_rkme_image_spec
from .base import Specification, BaseStatSpecification
from .image import RKMEImageStatSpecification
from .table import RKMEStatSpecification
from .regular import RKMEStatSpecification, RKMEImageStatSpecification

+ 2
- 5
learnware/specification/base.py View File

@@ -15,11 +15,8 @@ class BaseStatSpecification:
"""
self.type = type

def generate_stat_spec_from_data(self, **kwargs):
"""Construct statistical specification from raw dataset
- kwargs may include the feature, label and model
- kwargs also can include hyperparameters of specific method for specifaction generation
"""
def generate_stat_spec(self, **kwargs):
"""Construct statistical specification"""
raise NotImplementedError("generate_stat_spec_from_data is not implemented")

def save(self, filepath: str):


+ 2
- 0
learnware/specification/regular/__init__.py View File

@@ -0,0 +1,2 @@
from .table import RKMEStatSpecification
from .image import RKMEImageStatSpecification

+ 13
- 0
learnware/specification/regular/base.py View File

@@ -0,0 +1,13 @@
from ..base import BaseStatSpecification


class RegularStatsSpecification(BaseStatSpecification):
def generate_stat_spec(self, **kwargs):
self.generate_stat_spec_from_data(**kwargs)

def generate_stat_spec_from_data(self, **kwargs):
"""Construct statistical specification from raw dataset
- kwargs may include the feature, label and model
- kwargs also can include hyperparameters of specific method for specifaction generation
"""
raise NotImplementedError("generate_stat_spec_from_data is not implemented")

learnware/specification/image/__init__.py → learnware/specification/regular/image/__init__.py View File


learnware/specification/image/cnn_gp.py → learnware/specification/regular/image/cnn_gp.py View File


learnware/specification/image/rkme.py → learnware/specification/regular/image/rkme.py View File

@@ -122,7 +122,9 @@ class RKMEImageStatSpecification(BaseStatSpecification):
X[i] = torch.where(is_nan, img_mean, img)

if X.shape[2] != RKMEImageStatSpecification.IMAGE_WIDTH or X.shape[3] != RKMEImageStatSpecification.IMAGE_WIDTH:
X = Resize((RKMEImageStatSpecification.IMAGE_WIDTH, RKMEImageStatSpecification.IMAGE_WIDTH), antialias=None)(X)
X = Resize(
(RKMEImageStatSpecification.IMAGE_WIDTH, RKMEImageStatSpecification.IMAGE_WIDTH), antialias=None
)(X)

num_points = X.shape[0]
X_shape = X.shape

learnware/specification/table/__init__.py → learnware/specification/regular/table/__init__.py View File


learnware/specification/table/rkme.py → learnware/specification/regular/table/rkme.py View File

@@ -20,8 +20,8 @@ try:
except ImportError:
_FAISS_INSTALLED = False

from ..base import BaseStatSpecification
from ...logger import get_module_logger
from ..base import RegularStatsSpecification
from ....logger import get_module_logger

logger = get_module_logger("rkme")

@@ -30,7 +30,7 @@ if not _FAISS_INSTALLED:
logger.warning('Please run "conda install -c pytorch faiss-cpu" first.')


class RKMEStatSpecification(BaseStatSpecification):
class RKMEStatSpecification(RegularStatsSpecification):
"""Reduced Kernel Mean Embedding (RKME) Specification"""

def __init__(self, gamma: float = 0.1, cuda_idx: int = -1):

+ 0
- 0
learnware/specification/system/__init__.py View File


+ 15
- 0
learnware/specification/system/heter_table.py View File

@@ -0,0 +1,15 @@
from ..base import BaseStatSpecification


class HeterMapTableSpecification(BaseStatSpecification):
def generate_stat_spec(self, **kwargs):
pass

def save(self, filepath: str):
pass

def load(self, filepath: str):
pass

def dist(self, other_spec):
pass

+ 1
- 2
learnware/specification/utils.py View File

@@ -3,9 +3,8 @@ import numpy as np
import pandas as pd
from typing import Union

from .image import RKMEImageStatSpecification
from .base import BaseStatSpecification
from .table import RKMEStatSpecification
from .regular import RKMEStatSpecification, RKMEImageStatSpecification
from ..config import C




Loading…
Cancel
Save