Skip to content

Commit

Permalink
Merge pull request #34 from delve-team/develop
Browse files Browse the repository at this point in the history
Minor refactor, add docs, fix tests, etc.
  • Loading branch information
JustinShenk authored Aug 22, 2021
2 parents f805486 + 2bb55d8 commit e031478
Show file tree
Hide file tree
Showing 173 changed files with 1,817 additions and 360 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/draft-pdf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on: [push]

jobs:
paper:
runs-on: ubuntu-latest
name: Paper Draft
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build draft PDF
uses: openjournals/openjournals-draft-action@master
with:
journal: joss
# This should be the path to the paper within your repo.
paper-path: paper/paper.md
- name: Upload
uses: actions/upload-artifact@v1
with:
name: paper
# This is the output path where Pandoc will write the compiled
# PDF. Note, this should be the same directory as the input
# paper.md
path: paper/paper.pdf
53 changes: 53 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Tests

on:
push:
branches: [master]
tags: [v*]
pull_request:
branches: [master]

jobs:
miniconda:
name: Miniconda ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest"]
steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: test
channels: conda-forge,defaults
environment-file: environment.yml
python-version: 3.8
auto-activate-base: false
- shell: bash -l {0}
run: |
conda info
conda list
- name: Lint
shell: bash -l {0}
run: |
conda install flake8
python -m flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
python -m flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run pytest
shell: bash -l {0}
run: |
pip install -r requirements/dev.txt
pip install -r requirements/docs.txt
pip install --upgrade pytest flake8 sphinx
pip install scipy --force-reinstall # for https://github.com/conda/conda/issues/6396
pip install .
conda install pytest
py.test . --cov-report=xml --cov=delve -vvv
- name: Codecov
uses: codecov/codecov-action@v2.0.2
with:
flags: unittests
env_vars: OS,PYTHON
name: codecov-umbrella
fail_ci_if_error: false
verbose: false
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ ENV/
env.bak/
venv.bak/

# Sphinx documentation
docs/build/

# Spyder project settings
.spyderproject
.spyproject
Expand All @@ -106,3 +109,5 @@ venv.bak/
.DS_Store
.idea/
.vscode/

*.pickle
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-json
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-added-large-files
- id: requirements-txt-fixer
- repo: https://github.com/pre-commit/mirrors-yapf
rev: stable # Use the sha / tag you want to point at
hooks:
- id: yapf
- repo: local
hooks:
- id: flake8
name: flake8
entry: python -m pflake8
language: system
types: [python]
- repo: git://github.com/timothycrosley/isort
rev: 5.8.0
hooks:
- id: isort
args: [ "--profile", "black" ]
exclude: ^scripts/old_notebooks
13 changes: 13 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
sphinx:
configuration: docs/source/conf.py

formats: all

build:
image: latest

python:
version: 3.7
install:
- requirements: requirements/docs.txt
13 changes: 5 additions & 8 deletions delve/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
try:
import torch
from delve.torchcallback import CheckLayerSat

from delve.tools import reconstruct_csv_from_npy_data
from delve.torchcallback import CheckLayerSat
except ImportError:
pass
name = "delve"

try:
from delve.writers import PrintWriter as console
from delve.writers import NPYWriter as npy
try:
from delve.writers import CSVWriter as csv
from delve.writers import CSVandPlottingWriter as plot
from delve.writers import CSVandPlottingWriter as plotcsv

from delve.writers import CSVandPlottingWriter as csvplot
from delve.writers import NPYWriter as npy
from delve.writers import PrintWriter as console
from delve.writers import TensorBoardWriter as tensorboard
except ImportError:
pass
Expand Down
16 changes: 5 additions & 11 deletions delve/kerascallback.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import datetime
import logging

import keras
import numpy as np
import tensorflow as tf

from keras import backend as K

import numpy as np
from numpy.linalg import LinAlgError


Expand Down Expand Up @@ -104,7 +102,6 @@ class CustomTensorBoard(tf.keras.callbacks.TensorBoard):
specified for summary visualization.
kwargs: Passed to tf.keras.callbacks.TensorBoard.
"""

def __init__(self, user_defined_freq=0, **kwargs):
self.user_defined_freq = user_defined_freq
super(CustomTensorBoard, self).__init__(**kwargs)
Expand All @@ -126,7 +123,6 @@ def on_epoch_begin(self, epoch, logs=None):

super(CustomTensorBoard, self).on_epoch_begin(epoch, logs=None)


def on_epoch_end(self, epoch, logs=None):
"""Checks if summary ops should run next epoch, logs scalar summaries."""

Expand All @@ -150,7 +146,6 @@ class SaturationMetric(keras.callbacks.Callback):
input_data: sample input to calculate layer saturation with, eg train
print_freq
"""

def __init__(self, model, input_data, print_freq=1):
self.model = model
self.input_data = input_data
Expand All @@ -174,11 +169,11 @@ def on_epoch_end(self, epoch, logs):
if epoch > 2:
for layer in layers:
try:
print("epoch = %4d layer = %r sat = %0.2f%%" \
logging.info("epoch = %4d layer = %r sat = %0.2f%%" \
% (epoch, layer, logs[layer]))
logs[layer] = self.preactivation_states[layer]
except Exception as e:
print(e)
logging.error(e)


class SaturationLogger(keras.callbacks.Callback):
Expand All @@ -189,7 +184,6 @@ class SaturationLogger(keras.callbacks.Callback):
input_data: sample input to calculate layer saturation with, eg train
print_freq
"""

def __init__(self, model, input_data, print_freq=1):
self.model = model
self.input_data = input_data
Expand Down Expand Up @@ -219,4 +213,4 @@ def on_epoch_end(self, epoch, logs):
print_str = ""
for layer in layers:
print_str += "{:^10}: %{:4.2f} |".format(layer, logs[layer])
print(print_str)
logging.info(print_str)
1 change: 0 additions & 1 deletion delve/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,3 @@ def compute_diag_trace(cov: torch.Tensor) -> float:
eig_vals, eigen_space = cov.symeig(True)
eig_vals[eig_vals < 0] = 0
return eig_vals.sum().unsqueeze(dim=0).cpu().numpy()[0]

Loading

0 comments on commit e031478

Please sign in to comment.