Skip to content

Commit

Permalink
fix: examples updated (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
bagxi committed Aug 11, 2021
1 parent f43e751 commit cfa084c
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 78 deletions.
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ dataset:
_target_: torchvision.datasets.CIFAR100
root: ./data
train: false
transform:
_target_: torchvision.transforms.Compose
transforms:
- _target_: torchvision.transforms.ToTensor
- _target_: torchvision.transforms.Normalize
mean: [0.1307]
std: [0.3081]
download: true
```
Expand All @@ -55,10 +48,6 @@ config["dataset"]
# Root location: ./data
# Split: Test
# StandardTransform
# Transform: Compose(
# ToTensor()
# Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
# )
```

Please check [documentation](https://catalyst-team.github.io/hydra-slayer/master/pages/examples) for more examples.
Expand Down
167 changes: 100 additions & 67 deletions docs/pages/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,42 @@ Basic Level

<div>
<img src="../_static/basic_fire_magic.png" style="float: right; padding-left: 24px;" />
<p>Create <a href="https://www.cs.toronto.edu/~kriz/cifar.html">CIFAR100</a> dataset from config file with params.</p>
<p>Create instance from config file with params.</p>
<blockquote>Please note that <b>Basic Fire Magic</b> also allows your hero to cast fire spells at reduced cost.</blockquote>
</div>

.. code-block:: yaml
# transform.yaml
_target_: torchvision.transforms.Normalize
mean: [0.5, 0.5, 0.5]
std: [0.5, 0.5, 0.5]
.. code-block:: python
import hydra_slayer
import yaml
registry = hydra_slayer.Registry()
with open("dataset.yaml") as stream:
raw_config = yaml.safe_load(stream)
transform = registry.get_from_params(**raw_config)
transform
# Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
Advanced Level
^^^^^^^^^^^^^^

.. raw:: html

<div>
<img src="../_static/advanced_fire_magic.png" style="float: right; padding-left: 24px;" />
<p>Create <a href="https://www.cs.toronto.edu/~kriz/cifar.html">CIFAR100</a> dataset from config file with params.</p>
<blockquote>Please note that <b>Advanced Fire Magic</b> also allows your hero to cast fire spells at reduced cost and increased effectiveness.</blockquote>
</div>

.. code-block:: yaml
# dataset.yaml
Expand All @@ -26,8 +58,8 @@ Basic Level
transforms:
- _target_: torchvision.transforms.ToTensor
- _target_: torchvision.transforms.Normalize
mean: [0.1307]
std: [0.3081]
mean: [0.5, 0.5, 0.5]
std: [0.5, 0.5, 0.5]
download: true
.. code-block:: python
Expand All @@ -52,15 +84,15 @@ Basic Level
# )
Advanced Level
^^^^^^^^^^^^^^
Expert level
^^^^^^^^^^^^

.. raw:: html

<div>
<img src="../_static/advanced_fire_magic.png" style="float: right; padding-left: 24px;" />
<img src="../_static/expert_fire_magic.png" style="float: right; padding-left: 24px;" />
<p>Read multiple CSV files as pandas dataframes and merge them.</p>
<blockquote>Please note that <b>Advanced Fire Magic</b> also allows your hero to cast fire spells at reduced cost and increased effectiveness.</blockquote>
<blockquote>Please note that <b>Expert Fire Magic</b> also allows your hero to cast fire spells at reduced cost and maximum effectiveness.</blockquote>
</div>

.. code-block:: yaml
Expand Down Expand Up @@ -106,72 +138,73 @@ Advanced Level
# ... ... ... ...
Expert level
^^^^^^^^^^^^

.. raw:: html

<div>
<img src="../_static/expert_fire_magic.png" style="float: right; padding-left: 24px;" />
<p>Sorry, the person who is responsible for the expert level example was eaten by hydras last week.</p>
<blockquote>Please note that <b>Expert Fire Magic</b> also allows your hero to cast fire spells at reduced cost and maximum effectiveness.</blockquote>
</div>

..
.. code-block:: yaml
# dataset.yaml
_target_: torchvision.datasets.CIFAR100
root: ./data
train: false
transform:
_target_: torchvision.transforms.Compose
transforms:
- _target_: torchvision.transforms.ToTensor
- _target_: torchvision.transforms.Normalize
mean: [0.5,0.5,0.5]
std: [0.5,0.5,0.5]
download: true

.. code-block:: yaml
# config.yaml
dataset:
_target_: torch.utils.data.DataLoader
# TODO: will not work as dict will be retuned, not dataset
Master level
^^^^^^^^^^^^
.. raw:: html

<div>
<img src="../_static/expert_fire_magic.png" style="float: right; padding-left: 24px;" />
<p>Sorry, the person who is responsible for the expert level example was eaten by hydras last week.</p>
<blockquote>Please note that <b>Maximum Fire Magic</b> also allows your hero to cast fire spells at reduced cost and maximum effectiveness.</blockquote>
</div>

..
.. code-block:: yaml
# dataset.yaml
_target_: torchvision.datasets.CIFAR100
root: ./data
train: false
transform:
_target_: torchvision.transforms.Compose
transforms:
- _target_: torchvision.transforms.ToTensor
- _target_: torchvision.transforms.Normalize
mean: [0.5,0.5,0.5]
std: [0.5,0.5,0.5]
download: true

.. code-block:: yaml
# config.yaml
dataset:
# Read dataset from "dataset.yaml", roughly equivalent to
# with open("dataset.yaml") as stream:
# params = yaml.safe_load(stream)
_target_: yaml.safe_load
stream:
_target_: open
file: dataset_config.yaml
_target_: torch.utils.data.DataLoader
# TODO: will not work as dict will be retuned, not dataset
dataset:
# Read dataset from "dataset.yaml", roughly equivalent to
# with open("dataset.yaml") as stream:
# params = yaml.safe_load(stream)
_target_: yaml.safe_load
stream:
_target_: open
file: dataset_config.yaml
meta_factory:
_target_: hydra_slayer.call_meta_factory
batch_size: 32
shuffle: false
model:
_target_: torchvision.models.resnet18
pretrained: true
meta_factory:
_target_: hydra_slayer.call_meta_factory
batch_size: 32
shuffle: false
model:
_target_: torchvision.models.resnet18
pretrained: true
meta_factory:
_target_: hydra_slayer.call_meta_factory
.. code-block:: python
.. code-block:: python
import hydra_slayer
import torch
import yaml
import hydra_slayer
import torch
import yaml
registry = hydra_slayer.Registry()
with open("config.yaml") as stream:
raw_config = yaml.safe_load(stream)
registry = hydra_slayer.Registry()
with open("config.yaml") as stream:
raw_config = yaml.safe_load(stream)
config = registry.get_from_params(**raw_config)
model, dataset = config["model"], config["dataset"]
config = registry.get_from_params(**raw_config)
model, dataset = config["model"], config["dataset"]
model.eval()
with torch.no_grad():
for batch, y_true in dataset:
y_preds = model(batch)
model.eval()
with torch.no_grad():
for batch, y_true in dataset:
y_preds = model(batch)

0 comments on commit cfa084c

Please sign in to comment.