semvec/pypi-packages huggingface dataset:
torch-intermediate-layer-getter 0.1.post1
Simple easy to use module to get the intermediate results from chosen submodules

Simple easy to use module to get the intermediate results from chosen submodules. Supports submodule annidation. Inspired in [this](https://github.com/pytorch/vision/blob/f76e598d47879dbd917bf5936bbd11ff41632787/torchvision/models/_utils.py#L7) but does not assume that submodules are executed sequentially.

# Installation

```sh
pip install torch_intermediate_layer_getter
```

# Usage
## Example

```python
import torch
import torch.nn as nn

from torch_intermediate_layer_getter import IntermediateLayerGetter as MidGetter

class Model(nn.Module):
    def __init__(self):
        super().__init__()

        self.fc1 = nn.Linear(2, 2)
        self.fc2 = nn.Linear(2, 2)
        self.nested = nn.Sequential(
            nn.Sequential(nn.Linear(2, 2), nn.Linear(2, 3)),
            nn.Linear(3, 1),
        )
        self.interaction_idty = nn.Identity() # Simple trick for operations not performed as modules

    def forward(self, x):
        x1 = self.fc1(x)
        x2 = self.fc2(x)

        interaction = x1 * x2
        self.interaction_idty(interaction)

        x_out = self.nested(interaction)

        return x_out
        
model = Model()
return_layers = {
    'fc2': 'fc2',
    'nested.0.1': 'nested',
    'interaction_idty': 'interaction',
}
mid_getter = MidGetter(model, return_layers=return_layers, keep_output=True)
mid_outputs, model_output = mid_getter(torch.randn(1, 2))

print(model_output)
>> tensor([[0.3219]], grad_fn=<AddmmBackward>)
print(mid_outputs)
>> OrderedDict([('fc2', tensor([[-1.5125,  0.9334]], grad_fn=<AddmmBackward>)),
  ('interaction', tensor([[-0.0687, -0.1462]], grad_fn=<MulBackward0>)),
  ('nested', tensor([[-0.1697,  0.1432,  0.2959]], grad_fn=<AddmmBackward>))])

# model_output is None if keep_ouput is False
# if keep_output is True the model_output contains the final model's output
```
cyclist 0.0.8
Cycle-based data analysis toolbox

# cyclist
Event-based data analysis framework
v 0.0.1

Cyclist allows you to split dataframes at predetermined "events". For instance, with an EMG channel measured during exercise you may capture the moment flexion and extension happens via motion capture. You can input the timing of your flexion and extension events into dictionaries and pass that into the create cycles function which will return the EMG cycles cut from first event 1 to stop event 1, and then first event 2 to stop event 2. Or, pass the same event twice, which will split the file into multiple parts from each event. 

Class: eventDict, extends defaultdict

New eventDict:  
x = cyclist.eventDict()  

Explicit event creation:  
eventDict.add_event(name,time)  

Parse a dict of events:  
events = cyclist.parse_events(external_event_dict)  
external event dict must be a valid dictionary of form {'x':[1,2,3], 'two':[5.0,51,107]}  

Split data based on cycles:  
cyclist.create_cycles(data,eventDict,start,end)  
Loops over the data and cuts from:  
  Start 1 -> End 1  
  Start 2 -> End 2  
  ...  
  Start n -> End n  

  Returns a dataframe with len(data.columns) * n columns, with each column given a _n suffix