Skip to content
Permalink
Browse files

fix a bug in applying transform during inference

  • Loading branch information
lijunzh committed May 20, 2019
1 parent 5a8d7a8 commit 6d53884112eec20d3fd96cccfc6860c41185f1b8
Showing with 4 additions and 55 deletions.
  1. +1 −34 torch_rbp_install.rst
  2. +1 −19 yews/cpic/detection.py
  3. +2 −2 yews/cpic/utils.py
@@ -38,7 +38,7 @@ Prerequisities

.. code-block::

sudo apt install git cmake ninja
sudo apt install git cmake ninja gfortran


Berryconda
@@ -65,39 +65,6 @@ Berryconda
conda install cython m4 cmake pyyaml numpy
conda deactivate


Google Protobuf
---------------

Unfortunately, Google's protobuf does not have a conda pre-build package
available on armv7l platform. We will have to build it from source.

#. Download and install the protobuf from source:

.. code-block::

mkdir git & cd git
git clone https://github.com/protocolbuffers/protobuf
cd protobuf/python
conda activate
python setup.py install
conda deactivate
cd

#. Test installation

.. code-block::

conda activate
python
from google import protobuf
exit()
conda deactivate

Note:
If the protobuf can be properly imported, it is correctly installed.


PyTorch
-------

@@ -2,27 +2,9 @@
import torch
from scipy.special import expit

from .utils import compute_probs
from .utils import sliding_window_view


def compute_probs(model, transform, waveform, shape, step):
model.eval()
with torch.no_grad():
windows = sliding_window_view(waveform, shape, step)
windows = transform(np.squeeze(windows))
outputs = model(windows)

if next(model.parameters()).is_cuda:
outputs = outputs.cpu().numpy()
else:
outputs = outputs.numpy()

probs = expit(outputs).T
probs /= probs.sum(axis=0)

return probs


def find_nonzero_runs(a):
# source: https://stackoverflow.com/
# questions/31544129/extract-separate-non-zero-blocks-from-array
@@ -16,8 +16,8 @@ def probs2cfs(probs, sigma=3):
def compute_probs(model, transform, waveform, shape, step):
model.eval()
with torch.no_grad():
windows = sliding_window_view(waveform, shape, step)
windows = transform(np.squeeze(windows))
windows = np.squeeze(sliding_window_view(waveform, shape, step))
windows = np.stack([transform(window) for window in windows])
outputs = model(windows)

if next(model.parameters()).is_cuda:

0 comments on commit 6d53884

Please sign in to comment.
You can’t perform that action at this time.