Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-structure the project with standard template #27

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/CICD.yml
@@ -0,0 +1,68 @@
name: CICD

on: [push, pull_request]

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
make install
- name: Test
run: make test

pack:
name: Pack
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
make install
- name: Pack Testing
run: |
make dist
echo "To be add: pack testing"

deploy:
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/v'))
name: Deploy
needs: [build, pack]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
make install

- name: Is A Publish Branch
if: steps.check-branch.outputs.match == 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
make deploy-version
python setup.py sdist bdist_wheel
twine upload --skip-existing dist/*

- name: Is Not A Publish Branch
if: steps.check-branch.outputs.match != 'true'
run: echo 'Not A Publish Branch'
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -123,4 +123,4 @@ FETCH_HEAD
# vscode
.vscode
*.DS_Store
PaddleFSL/raw_data/
raw_data/
File renamed without changes.
4 changes: 0 additions & 4 deletions FewShotPapers/README.md
Expand Up @@ -2891,7 +2891,3 @@ and L. Van Gool.*
1. **keras-fsl,** a library for few-shot learning written in *Tensorflow*.
[link](https://github.com/few-shot-learning/Keras-FewShotLearning)





File renamed without changes.
1 change: 1 addition & 0 deletions MAINTAINERS
@@ -0,0 +1 @@
Yaqing Wang (王雅晴) <wangyaqing01@baidu.com>
3 changes: 3 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,3 @@
include LICENSE README.md VERSION
recursive-include PaddleFSL *.py
recursive-exclude test *
124 changes: 124 additions & 0 deletions Makefile
@@ -0,0 +1,124 @@
SOURCE_GLOB=$(wildcard bin/*.py src/**/*.py tests/**/*.py examples/*.py)

IGNORE_PEP=E203,E221,E241,E272,E501,F811

export PYTHONPATH=PaddleFSL


.PHONY: all
all : clean lint

.PHONY: clean
clean:
rm -fr dist/* .pytype ./build/ dist/

.PHONY: lint
lint: pylint pycodestyle flake8 mypy


.PHONY: pylint
pylint:
pylint \
--load-plugins pylint_quotes \
--disable=W0511,R0801,cyclic-import,C4001 \
$(SOURCE_GLOB)

.PHONY: pycodestyle
pycodestyle:
pycodestyle \
--statistics \
--count \
--ignore="${IGNORE_PEP}" \
$(SOURCE_GLOB)

.PHONY: flake8
flake8:
flake8 \
--ignore="${IGNORE_PEP}" \
$(SOURCE_GLOB)

.PHONY: mypy
mypy:
MYPYPATH=stubs/ mypy \
$(SOURCE_GLOB)

.PHONY: pytype
pytype:
pytype \
-V 3.8 \
--disable=import-error,pyi-error \
src/
pytype \
-V 3.8 \
--disable=import-error \
examples/

.PHONY: uninstall-git-hook
uninstall-git-hook:
pre-commit clean
pre-commit gc
pre-commit uninstall
pre-commit uninstall --hook-type pre-push

.PHONY: install-git-hook
install-git-hook:
# cleanup existing pre-commit configuration (if any)
pre-commit clean
pre-commit gc
# setup pre-commit
# Ensures pre-commit hooks point to latest versions
pre-commit autoupdate
pre-commit install
pre-commit install --hook-type pre-push

.PHONY: install
install:
pip3 install -r requirements.txt
pip3 install -r requirements-dev.txt
$(MAKE) install-git-hook

.PHONY: pytest
pytest:
pytest src/ test/

.PHONY: test-unit
test-unit: pytest

.PHONY: test
test:
echo "No test for PaddleFSL which don't follow the lint & test guides"
# check-python-version lint pytest

.PHONY: check-python-version
check-python-version:
./scripts/check_python_version.py

.PHONY: dist
dist:
make clean
python3 setup.py sdist bdist_wheel

.PHONY: publish
publish:
PATH=~/.local/bin:${PATH} twine upload dist/*

.PHONY: version
version:
@newVersion=$$(awk -F. '{print $$1"."$$2"."$$3+1}' < VERSION) \
&& echo $${newVersion} > VERSION \
&& git add VERSION \
&& git commit -m "🔥 update version to $${newVersion}" > /dev/null \
&& git tag "v$${newVersion}" \
&& echo "Bumped version to $${newVersion}"

.PHONY: deploy-version
deploy-version:
echo "VERSION = '$$(cat VERSION)'" > paddlefsl/version.py

.PHONY: doc
doc:
mkdocs serve

.PHONY: anil-text
anil-text:
python ./PaddleFSL/examples/optim/anil_text_classification.py
86 changes: 0 additions & 86 deletions PaddleFSL/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions PaddleFSL/env.sh

This file was deleted.

46 changes: 46 additions & 0 deletions PaddleFSL/examples/optim/README_temp.md
@@ -0,0 +1,46 @@
# Image Classification Tasks

Here, we provide examples of applying PaddleFSL to few-shot image classification tasks which is similarity to example with [model_zoo](../image_classification/README.md).


## Datasets

We evaluate the performance on 5 benchmark datasets, including Omniglot, *mini*ImageNet, CIFAR-FS, FC100 and Tiered-ImageNet, which can be accessed as described in [raw_data/README.md](../../raw_data/README.md).

## Results

We provide results of using MAML [1], ANIL [2] below. The exact model configuration and pretrained models can be downloaded from [here](https://drive.google.com/file/d/1pmCI-8cwLsadG6JOcubufrQ2d4zpK9B-/view?usp=sharing), which can reproduce these results.

### [MAML](http://proceedings.mlr.press/v70/finn17a/finn17a.pdf?source=post_page---------------------------)


| Dataset | Backbone | Way | Shot | Original paper | Other reports | model zoo(first order) | Optim(first order) |
| :-------------: | :------: | :--: | :--: | :------------: | :----------------------------------------------------------: | :--------------------: | ------------------ |
| Omniglot | MLP | 5 | 1 | 89.7 ± 1.1 | 88.9<br>([learn2learn](http://learn2learn.net/)) | 88.88 ± 2.99 | -- |
| Omniglot | MLP | 5 | 5 | 97.5 ± 0.6 | -- | 97.50 ± 0.47 | -- |
| Omniglot | CNN | 5 | 1 | 98.7 ± 0.4 | 99.1<br/>([learn2learn](http://learn2learn.net/)) | 97.13 ± 1.25 | 92.7 |
| Omniglot | CNN | 5 | 5 | 99.9 ± 0.1 | 99.9 ± 0.1<br/>([R2D2](https://arxiv.org/pdf/1805.08136.pdf)) | 99.23 ± 0.40 | ***93.1*** |
| *mini*ImageNet | CNN | 5 | 1 | 48.70 ± 1.84 | 48.3<br/>([learn2learn](http://learn2learn.net/)) | 49.81 ± 1.78 | |
| *mini*ImageNet | CNN | 5 | 5 | 63.11 ± 0.92 | 65.4<br/>([learn2learn](http://learn2learn.net/)) | 64.21 ± 1.33 | -- |
| CIFAR-FS | CNN | 5 | 1 | -- | 58.9 ± 1.9<br/>([R2D2](https://arxiv.org/pdf/1805.08136.pdf)) | 57.06 ± 3.83 | 49.1 |
| CIFAR-FS | CNN | 5 | 5 | -- | 76.6<br/>([learn2learn](http://learn2learn.net/)) | 72.24 ± 1.71 | -- |
| FC100 | CNN | 5 | 1 | -- | -- | 37.63 ± 2.23 | 30.2 |
| FC100 | CNN | 5 | 5 | -- | 49.0<br/>([learn2learn](http://learn2learn.net/)) | 49.14 ± 1.58 | -- |
| CUB | CNN | 5 | 1 | -- | 54.73 ± 0.97<br/>([CloseLookFS](https://arxiv.org/pdf/1904.04232.pdf)) | 53.31 ± 1.77 | 20.7 |
| CUB | CNN | 5 | 5 | -- | 75.75 ± 0.76<br/>([CloseLookFS](https://arxiv.org/pdf/1904.04232.pdf)) | 69.88 ± 1.47 | -- |
| Tiered-ImageNet | CNN | 5 | 5 | -- | -- | 67.56 ± 1.80 | -- |

### [ANIL](https://openreview.net/pdf?id=rkgMkCEtPB)

| Dataset | Backbone | Way | Shot | Author Report | Other Report | model zoo(first order) | Optimizer(First Order) |
| :------------: | :------: | :--: | :--: | :-----------: | :-----------------------------------------------: | :--------------------: | ---------------------- |
| Omniglot | CNN | 5 | 1 | -- | -- | 96.06 ± 1.00 | 96.34 ± 1.98 |
| Omniglot | CNN | 5 | 5 | -- | -- | 98.74 ± 0.48 | |
| *mini*ImageNet | CNN | 5 | 1 | 46.7 ± 0.4 | -- | 48.31 ± 2.83 | 45.31 ± 1.43 |
| *mini*ImageNet | CNN | 5 | 5 | 61.5 ± 0.5 | -- | 62.38 ± 1.96 | 61.81 ± 1.2 |
| CIFAR-FS | CNN | 5 | 1 | -- | -- | 56.19 ± 3.39 | ***30.8 ± 2.5*** |
| CIFAR-FS | CNN | 5 | 5 | -- | 68.3<br/>([learn2learn](http://learn2learn.net/)) | 68.60 ± 1.25 | 48.6 |
| FC100 | CNN | 5 | 1 | -- | -- | 40.69 ± 3.32 | 38.4 ± 1.3 |
| FC100 | CNN | 5 | 5 | -- | 47.6<br/>([learn2learn](http://learn2learn.net/)) | 48.01 ± 1.22 | 35.0 |
| CUB | CNN | 5 | 1 | -- | -- | 53.25 ± 2.18 | -- |
| CUB | CNN | 5 | 5 | -- | -- | 69.09 ± 1.12 | -- |
Expand Up @@ -6,7 +6,7 @@
from paddle.optimizer import Adam
import paddlefsl
from paddlefsl.metaopt.anil import ANILLearner
from examples.optim.meta_trainer import Config, Trainer, load_datasets
from examples.optim.tools.meta_trainer import Config, Trainer, load_datasets


def init_models(config: Config):
Expand Down Expand Up @@ -106,7 +106,7 @@ def init_models(config: Config):
if __name__ == '__main__':

config = Config().parse_args(known_only=True)
config.device = 'gpu'
config.device = 'cpu'
config.k_shot = 1

# config.dataset = 'omniglot'
Expand All @@ -115,9 +115,6 @@ def init_models(config: Config):
# config.dataset = 'fc100'
# config.dataset = 'cub'

config.tracking_uri = os.environ.get('TRACKING_URI', None)
config.experiment_id = os.environ.get('EXPERIMENT_ID', None)

# Config: ANIL, Omniglot, Conv, 5 Ways, 1 Shot
train_dataset, valid_dataset, test_dataset = load_datasets(config.dataset)
feature_model, head_layer = init_models(config)
Expand Down