Skip to content

Commit

Permalink
Merge branch 'release-v0.11.2' into 'stable'
Browse files Browse the repository at this point in the history
Release v0.11.2

See merge request secml/secml!12
  • Loading branch information
m-melis committed Jan 7, 2020
2 parents 8b145f1 + 95a5ca4 commit a4eefae
Show file tree
Hide file tree
Showing 27 changed files with 1,059 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ test:notebooks:py35:latest:
when: on_success
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_COMMIT_REF_NAME == "develop" || $CI_COMMIT_REF_NAME =~ /^release-.*$/ || $CI_COMMIT_REF_NAME =~ /^.*-stable$/'
- if: '$CI_COMMIT_REF_NAME == "develop" || $CI_COMMIT_REF_NAME == "master" || $CI_COMMIT_REF_NAME == "stable" || $CI_COMMIT_REF_NAME =~ /^release-.*$/ || $CI_COMMIT_REF_NAME =~ /^.*-stable$/'
changes:
- src/secml/**/*
- .gitlab-ci.yml
Expand Down
22 changes: 21 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
## v0.11.2 (07/01/2020)
- This version brings fixes for a few reported issues with `CAttack` and subclasses, along with the new Developers and Contributors guide.

### Requirements (1 change)
- #700 Temporarily pinned `Pillow` to v6 to avoid breaking `torch` and `torchvision` packages.

### Fixed (7 changes)
- #698 Fixed `CAttackEvasionCleverhans` definition of `class_type`.
- #662 The number of function and gradient evaluations made during double initialization in `CAttackEvasionPGDLS` are now correctly considered by `.f_eval` and `.grad_eval` properties.
- #699 Fixed batch processing in `CClassifierPyTorch` not working properly if the number of samples to be classified is not a multiple of `batch_size`.
- #691 Function and gradient evaluation counts in `CAttackEvasionCleverhans` returned by `.f_eval` and `.grad_eval` properties now only consider the last optimized sample, consistently with other `CAttack` subclasses.
- #701 Default value of `double_init` parameter in `CAttackEvasionPGDLS` set to True as originally intended.
- #684 The solution returned by `COptimizerPGD` is now always the best one found during the minimization process.
- #697 Fixed unittests failing under numpy v1.18 due to a change in the errors raised by `genfromtxt`.

### Documentation (2 changes)
- #671 Added Developers and Contributors guide.
- #694 Added a new notebook tutorial on advanced evasion attacks using Deep Neural Networks and ImageNet dataset.


## v0.11.1 (18/12/2019)
- Fixed compatibility issues with recently released scikit-learn v0.22 and scipy v1.4.

Expand Down Expand Up @@ -137,4 +157,4 @@ This version does not contain any significant change.


## v0.8 (06/08/2019)
- First public release!
- First public release!
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Contributing to SecML
=====================

The contributing and developer's guide is available in the repository at
`docs/source/developers/index.rst`, or online at:

https://secml.gitlab.io/developers/

References
----------
* [SecML Releases](https://gitlab.com/secml/secml/releases)
* [Bugs and new features tracker](https://gitlab.com/secml/secml/issues)
* [Coding Guidelines](http://secml.gitlab.io/developers/contributing.code.html#coding-guidelines)
* [Creating Extensions](http://secml.gitlab.io/developers/contributing.extensions.html)
50 changes: 3 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,54 +148,10 @@ The `secml.figure` package contains a visualization and plotting framework
based on [matplotlib](https://matplotlib.org/).


## Contributors
## Developers and Contributors

**Your contribution is foundamental!**

If you want to help the development of SecML, just set up the project locally
by the following means:

1. _(devs only)_ Install from local GitLab repository:
- Clone the project repository in a directory of your choice
- Run installation as: `pip install .`

2. _(devs only)_ Install from remote GitLab repository. In this case, given
`{repourl}` in the format, es., `gitlab.com/secml/secml`:
- `pip install git+ssh://git@{repourl}.git[@branch]#egg=secml`
A specific branch to install can be specified using `[@branch]` parameter.
If omitted, the default branch will be installed.

Contributions can be sent in the form of a merge request via our
[GitLab issue tracker](https://gitlab.com/secml/secml/issues).

SecML can also be added as a dependency for other libraries/project.
Just add `secml` or the full repository path command
`git+ssh://git@{repourl}.git[@branch]#egg=secml` to the `requirements.txt` file.

#### Editable Installation (development mode)

For SecML developers or users want to use the latest `dev` version
of the library, `pip` provides a convenient option which is called: **editable mode**.

By calling `pip install` with the `-e` option or `python setup.py develop`,
only a reference to the project files is "installed" in the active
environment. In this way, project files can be edited/updated and the
new versions will be automatically executed by the Python interpreter.

Two common scenarios are listed below:

1. Editable install from a previously cloned local repository
- Navigate to the repository directory
- Run `python setup.py develop`

2. Editable install from remote repository
- Run `pip install -e git+ssh://git@{repourl}.git[@branch]#egg=secml`
- Project will be cloned automatically in `<venv path>/src/secml`
- The new repository can then be updated using standard `git` commands

Editable installs are also available while using SecML as a
dependency of other libraries/projects
(see [Installation Guide](#installation-guide) for more information).
The contributing and developer's guide is available at:
https://secml.gitlab.io/developers/


## Authors
Expand Down
142 changes: 142 additions & 0 deletions docs/source/developers/contributing.code.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
##################
Code Contributions
##################

Contribution consisting on new code the library are much welcome.
One of our maintainers will review the contributions and will help
with the needed changes before integration, if any.

Development Installation
========================

Start by creating a `fork <https://gitlab.com/secml/secml/-/forks/new>`_
of our repository. Then, set up the project locally by the following means:

1. Install from local GitLab repository:

- Clone the project repository in a directory of your choice
- Run installation as: ``pip install .``

2. Install from remote GitLab repository. In this case, given ``{repourl}``
in the format, es., ``gitlab.com/secml/secml``:

- ``pip install git+ssh://git@{repourl}.git[@branch]#egg=secml``
A specific branch to install can be specified using ``[@branch]`` parameter.
If omitted, the default branch will be installed.

Contributions can be sent in the form of a merge request via our
`GitLab issue tracker <https://gitlab.com/secml/secml/issues>`_.
See `how to create a merge request <https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html>`_
guide for more information.

Editable Installation
---------------------

For SecML developers or users want to use the latest ``dev`` version of
the library (soon available to the public), ``pip`` provides a convenient
option which is called: **editable mode**.

By calling ``pip install`` with the ``-e`` option or ``python setup.py develop``,
only a reference to the project files is "installed" in the active
environment. In this way, project files can be edited/updated and the
new versions will be automatically executed by the Python interpreter.

Two common scenarios are listed below:

1. Editable install from a previously cloned local repository

- Navigate to the repository directory
- Run ``python setup.py develop``

2. Editable install from remote repository

- Run ``pip install -e git+ssh://git@{repourl}.git[@branch]#egg=secml``
- Project will be cloned automatically in ``<venv path>/src/secml``
- The new repository can then be updated using standard ``git`` commands

Merge request checklist
=======================

Please follow this checklist before sending a new merge request:

1. Use informative names for classes, methods, functions and variables.
2. Make sure your code passes the existing tests.
Remember to test both CPU and GPU (CUDA) mode, if applicable.
3. Make sure your code is well documented and commented when possible.
Make sure the documentation renders properly by compiling it.
4. Add tests if you are contributing to a new feature.
5. Make sure your code does not violate `PEP-8 <https://www.python.org/dev/peps/pep-0008/>`_
codestyle convention.
6. When applicable, re-use the code in the library without rewriting
procedures that are already implemented somewhere else.
7. (optional) Provide an example of usage in the merge request, so that
the contribution to the library will become clear to
the reviewers as well as other contributors.

Coding guidelines
=================

In this section, we summarize standards and conventions used in our library.

Code style
----------

We follow python `PEP-8 <https://www.python.org/dev/peps/pep-0008/>`_
convention for ensuring code readability. 4-spaces indentation should be used.

Documentation style
-------------------

We use informative docstrings for our code. Make sure your code is always
commented and documented. The docstrings should follow the
`NumPy documentation format <https://numpydoc.readthedocs.io/en/latest/format.html>`_.

To locally build the documentation, run the following command:
``tox -e docs``.

Compiled files will be available in the ``docs/build/html`` folder.

Packages
--------

Our packages are nested inside macro-categories. Every package can contain
modules, other packages or just directories for keeping everything structured
and tidy.

Modules
-------

We use separate files for each class so that they can be easily
found within the package structure. Modules can also be created to group
utility functions together.

Classes
-------

Our class names all start with ``C + <class_name>``, e.g. ``CClassifier``.
Hidden utility classes, accessible only internally from other classes,
have names starting with underscores (``_C + <class_name>``).

The packages's superclass often expose public methods that call inner
abstract methods. If you are subclassing one of these classes, take care of
reading the superclass code and check out the inner methods that you need
to implement. See: `Extending SecML <contributing.extensions.html>`_.

Tests
-----

We test our code with pervasive unit tests, build on Python's
`unittest <https://docs.python.org/3/library/unittest.html>`_ framework.
Existing unittests can be run using `tox <https://tox.readthedocs.io/>`_.

You can also contribute to writing tests for our code. We have ``tests``
subdirectories in all our packages.

The main interface from which new tests should be inherited is the
:class:`secml.testing.c_unittest.CUnitTest` class.

Tests should run smoothly and fast, performing accurate initialization and
cleanup. Implement the initialization in the ``setUp`` method,
and the single test cases in other separate methods.

New test modules should be have name starting with ``test_``.
69 changes: 69 additions & 0 deletions docs/source/developers/contributing.extensions.cclassifier.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
CClassifier
===========

The unified interface :class:`CClassifier` defines the structure of classifiers.

We differentiate a standard classifier from Deep Neural Networks (DNNs),
which require a more advanced interface defined by :class:`CClassifierDNN`
(described below).

Standard classifiers (``CClassifier``)
--------------------------------------

List of methods to implement:

- ``_forward``: performs a forward pass of the input x.
It should return the output of the decision function of the classifier.

- ``_backward``: this method returns the gradient of the decision function
output with respect to data. It takes a ``CArray`` as input, ``w``,
which pre-multiplies the gradient as in standard reverse-mode autodiff.

- ``_fit``: fit the classifier on the data. Takes as input a ``CDataset``.

DNN backends (``CClassifierDNN``)
---------------------------------

The backend for DNN (:class:`CClassifierDNN`) is based on the ``CClassifier``
interface, adding more methods specific to DNNs and their frameworks.

An example of how to extend the ``CClassifierDNN`` interface is our
PyTorch wrapper :class:`CClassifierPyTorch`.

List of methods to implement:

- ``_forward``: performs a forward pass of the input x. It is slightly
different from the ``_forward`` method of ``CClassifier``, as it returns
the output of the layer of the DNN specified in the attribute ``_out_layer``.
If ``_out_layer`` is ``None``, the last layer output is returned (applies
the softmax if ``softmax_outputs`` is True).

- ``_backward``: returns the gradient of the output of the DNN layer specified
in ``_out_layer``, with respect to the input data.

- ``_fit``: trains the classifier. Takes as input a ``CDataset``.

- ``layers`` (property): returns a list of tuples containing the layers of the
model, each tuple is structured as ``(layer_name, layer)``.

- ``layer_shapes`` (property): returns the output shape of each layer
(as a dictionary with layer names as keys).

- ``_to_tensor``: converts a ``CArray`` into the tensor data type of the
backend framework.

- ``_from_tensor``: converts a backend tensor data type to a ``CArray``.

- ``save_model``: saves the model weight and parameters into a gz archive.
If possible, it should allow model restoring as a checkpoint, i.e. the user
should be able to continue training of the restored model.

- ``load_model``: restores the model. If possible, it restores also the
optimization parameters as the user may need to continue training.

It may be necessary to implement a custom data loader for the specific DNN
backend. The data loader should take as input a ``CDataset`` and load the data
for the backend. This is necessary because the inputs to the network may have
their own shapes, whereas the ``CArray`` treats each sample as a row vector.
We suggest to add the ``input_shape`` as an input parameter of the wrapper
and handle the conversion inside.
70 changes: 70 additions & 0 deletions docs/source/developers/contributing.extensions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
###############
Extending SecML
###############

We provide details on how to implement new library modules, extending our
abstract interfaces.

Remember to check out
`latest version <https://gitlab.com/secml/secml/-/releases>`_ and
`roadmap <https://secml.gitlab.io/roadmap.html>`_ before developing new code.

Abstract Base Classes
=====================

The packages's abstract superclasses (e.g. :class:`CClassifier`) expose
public methods that call inner abstract methods. If you are creating a new
extension, inherit from one of these classes, taking care of reading the
superclass code and check out the inner methods that you need to implement.

New extensions should handle our main data type :class:`CArray`.
This class wraps the dense numpy :class:`numpy.ndarray` and the scipy sparse
:class:`scipy.sparse.csr_matrix`, so that they have the same interface
for the user.

The shape of a ``CArray`` is either a vector or a matrix (multi-dimensional
arrays will be added in a future version) of rows where each row represents
a sample.

Two ``CArray`` are needed to compose a :class:`CDataset`
that can be used to store samples (attribute X) and labels (attribute Y).

Creating new extensions
=======================

The following guides illustrate how to extend the superclasses for the
different packages of the library:

.. toctree::
:hidden:

contributing.extensions.cclassifier


* `CClassifier <contributing.extensions.cclassifier.html>`_ -
classifiers including Deep Neural Networks.

The following contribution guides will be added in a future versions.

* Data processing

- :class:`CPreprocess`
- :class:`CKernel`

* Data

- :class:`CDataLoader`

* Visualization

- :class:`CPlot`

* Attacks

- :class:`CAttack`
- :class:`CAttackEvasion`
- :class:`CAttackPoisoning`

* Optimization

- :class:`COptimizer`

0 comments on commit a4eefae

Please sign in to comment.