{"id":13568451,"url":"https://github.com/catalyst-team/catalyst-info","last_synced_at":"2025-04-04T04:31:01.618Z","repository":{"id":95655250,"uuid":"203868694","full_name":"catalyst-team/catalyst-info","owner":"catalyst-team","description":null,"archived":true,"fork":false,"pushed_at":"2020-04-14T17:10:30.000Z","size":909,"stargazers_count":27,"open_issues_count":0,"forks_count":1,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-29T12:35:12.344Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/catalyst-team.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":null,"patreon":"catalyst_team","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-08-22T20:32:03.000Z","updated_at":"2024-01-04T16:37:03.000Z","dependencies_parsed_at":"2023-03-04T01:00:31.898Z","dependency_job_id":null,"html_url":"https://github.com/catalyst-team/catalyst-info","commit_stats":{"total_commits":21,"total_committers":3,"mean_commits":7.0,"dds":"0.47619047619047616","last_synced_commit":"7b95df44ce1bdb57083dfa214e3717b314ff4f08"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catalyst-team%2Fcatalyst-info","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catalyst-team%2Fcatalyst-info/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catalyst-team%2Fcatalyst-info/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catalyst-team%2Fcatalyst-info/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/catalyst-team","download_url":"https://codeload.github.com/catalyst-team/catalyst-info/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246981161,"owners_count":20863828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T14:00:26.100Z","updated_at":"2025-04-04T04:31:01.597Z","avatar_url":"https://github.com/catalyst-team.png","language":null,"funding_links":["https://patreon.com/catalyst_team"],"categories":["Tutorials and Pipelines","Others"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n[![Catalyst logo](https://raw.githubusercontent.com/catalyst-team/catalyst-pics/master/pics/catalyst_logo.png)](https://github.com/catalyst-team/catalyst)\n\n**Accelerated DL R\u0026D**\n\n[![Build Status](http://66.248.205.49:8111/app/rest/builds/buildType:id:Catalyst_Deploy/statusIcon.svg)](http://66.248.205.49:8111/project.html?projectId=Catalyst\u0026tab=projectOverview\u0026guest=1)\n[![CodeFactor](https://www.codefactor.io/repository/github/catalyst-team/catalyst/badge)](https://www.codefactor.io/repository/github/catalyst-team/catalyst)\n[![Pipi version](https://img.shields.io/pypi/v/catalyst.svg)](https://pypi.org/project/catalyst/)\n[![Docs](https://img.shields.io/badge/dynamic/json.svg?label=docs\u0026url=https%3A%2F%2Fpypi.org%2Fpypi%2Fcatalyst%2Fjson\u0026query=%24.info.version\u0026colorB=brightgreen\u0026prefix=v)](https://catalyst-team.github.io/catalyst/index.html)\n[![PyPI Status](https://pepy.tech/badge/catalyst)](https://pepy.tech/project/catalyst)\n\n[![Twitter](https://img.shields.io/badge/news-on%20twitter-499feb)](https://twitter.com/catalyst_core)\n[![Telegram](https://img.shields.io/badge/channel-on%20telegram-blue)](https://t.me/catalyst_team)\n[![Slack](https://img.shields.io/badge/Catalyst-slack-success)](https://join.slack.com/t/catalyst-team-core/shared_invite/zt-d9miirnn-z86oKDzFMKlMG4fgFdZafw)\n[![Github contributors](https://img.shields.io/github/contributors/catalyst-team/catalyst.svg?logo=github\u0026logoColor=white)](https://github.com/catalyst-team/catalyst/graphs/contributors)\n\n\u003c/div\u003e\n\nPyTorch framework for Deep Learning research and development.\nIt was developed with a focus on reproducibility,\nfast experimentation and code/ideas reusing.\nBeing able to research/develop something new,\nrather than write another regular train loop. \u003cbr/\u003e\nBreak the cycle - use the Catalyst!\n\nProject [manifest](https://github.com/catalyst-team/catalyst/blob/master/MANIFEST.md). Part of [PyTorch Ecosystem](https://pytorch.org/ecosystem/). Part of [Catalyst Ecosystem](https://docs.google.com/presentation/d/1D-yhVOg6OXzjo9K_-IS5vSHLPIUxp1PEkFGnpRcNCNU/edit?usp=sharing):\n- [Alchemy](https://github.com/catalyst-team/alchemy) - Experiments logging \u0026 visualization\n- [Catalyst](https://github.com/catalyst-team/catalyst) - Accelerated Deep Learning Research and Development\n- [Reaction](https://github.com/catalyst-team/reaction) - Convenient Deep Learning models serving\n\n[Catalyst at AI Landscape](https://landscape.lfai.foundation/selected=catalyst).\n\n----\n\nYou can suggest a topic for the next release via [telegram](https://t.me/catalyst_team) or [twitter](https://twitter.com/catalyst_core) 😉\n\nCheck also our maintained [Awesome list](https://github.com/catalyst-team/awesome-catalyst-list)\n\n## Contents\n* **[#5 Callbacks](#catalyst-info-5-callbacks)**\n* **[#4. Ecosystem](#catalyst-info-4-ecosystem)**\n* **[#3. Runners](#catalyst-info-3-runners)**\n* **[#2. Tracing with Torch.Jit](#catalyst-info-2-tracing-with-torchjit)**\n* **[#1. Segmentation models](#catalyst-info-1-segmentation-models)**\n\n## Catalyst-info #5. Callbacks\ncatalyst-version: `19.11` date: `2019-11-07`\n\nHi, everybody! It's November, there's a new version [19.11](https://github.com/catalyst-team/catalyst/releases/tag/v19.11) and we're back with the new Catalyst-info. The topic is [Callbacks](https://github.com/catalyst-team/catalyst/tree/master/catalyst/dl/callbacks).\n\n---\n\nLet's look at the minimalistic train-loop for PyTorch:\n\n![image 5.1](./pics/5/train_loop.png)\n\nWe do a lot of nested iterations, going through different learning stages (warmup, train, finetune, etc.), iterate by epochs, iterate by all our dataloaders (train, valid, etc.) and finally, process batches inside each dataloader in some way.\n\nThis works, but how to make it customizable? To be able to add the necessary logic over the standard train-loop, we have introduced the Callbacks.\n\n---\nAny [callback](https://github.com/catalyst-team/catalyst/blob/b1d71998e8dad7604a3eb3ff0279fb275b8ae7e2/catalyst/dl/core/callback.py#L24) is the inherited of the `catalyst.dl.core.Callback` class with one or more methods implemented:\n\n![image 5.2](./pics/5/callback_methods.png)\n_From ML-REPA #2 [Deep dive into Catalyst by Roman Tezikov](https://docs.google.com/presentation/d/10dJqTGEPxk_gYKCZZdFqHHhuPUwwKNYdRhvuNphpy5E/edit?usp=sharing)_\n\nBy implementing these methods you can make any additional logic possible.\n\n---\nEach method takes `catalyst.dl.core.RunnerState`:\n```python\ndef on_stage_start(self, state: RunnerState):\n    pass\n\ndef on_stage_end(self, state: RunnerState):\n    pass\n```\n\nThis [class](https://github.com/catalyst-team/catalyst/blob/master/catalyst/dl/core/state.py#L13) is a mediator for communication between [Runner](https://github.com/catalyst-team/catalyst-info#catalyst-info-3-runners) and Callbacks. Inside it, there are such important things as the current loader `state.loader_name`, the input batch `state.input`, the output of the model `state.output`, which metric is used in the pipeline `state.main_metric`, whether it needs to be minimized `state.minimize_metric` and many others.\nAny parameter from `RunnerState` can be used in any callback.\n\nThe runner takes the Callbacks from Experiment and [invokes](https://github.com/catalyst-team/catalyst/blob/d629b26fa52b7442c433aadc72a47a109e0dd6d6/catalyst/dl/core/runner.py#L108) them. There can be a lot of callbacks per Experiment.\n\n---\nA lot of callbacks are already available from the \"box\", for example:\n\n- CheckpointCallback to [save](https://github.com/catalyst-team/catalyst/blob/master/catalyst/dl/callbacks/checkpoint.py#L164) the best / last checkpoint\n- TensorboardLogger for [logging](https://github.com/catalyst-team/catalyst/blob/master/catalyst/dl/callbacks/logging.py#L185) metrics in tensorboard\n- EarlyStoppingCallback for an [early exit](https://github.com/catalyst-team/catalyst/blob/master/catalyst/dl/callbacks/misc.py#L33) if the metric has stopped changing\n- AccuracyCallback / AUCCallback / PrecisionRecallF1ScoreCallback - classification metrics\n- DiceCallback / IouCallback - segmentation metrics\n- and many others.\n\nA complete list of prepared callbacks can be received by executing the command:\n```python\n\u003e\u003e\u003e from catalyst.dl.registry import CALLBACKS\n\u003e\u003e\u003e CALLBACKS\n```\n\n---\nHow are _system calls_ executed inside the trainloop, for example, `optimizer.step()`?\n\nIn Catalyst's philosophy even such things are also a call-up of certain callbacks. For example:\n- [CriterionCallback](https://github.com/catalyst-team/catalyst/blob/aae8ac9e189b332fd1a0ca32c6dda48893432169/catalyst/dl/callbacks/criterion.py#L32) calculates the loss values on `on_batch_end` (there can be many)\n- [CriterionAggregatorCallback](https://github.com/catalyst-team/catalyst/blob/aae8ac9e189b332fd1a0ca32c6dda48893432169/catalyst/dl/callbacks/criterion.py#L101) aggregates all losses into one \n by addition or by multiplication\n- [OptimizerCallback](https://github.com/catalyst-team/catalyst/blob/725000e077c91ae33ecc43f2c75fffba79688561/catalyst/dl/callbacks/optimizer.py#L16) takes the optimizer step after the loss\n- [SchedulerCallback](https://github.com/catalyst-team/catalyst/blob/aae8ac9e189b332fd1a0ca32c6dda48893432169/catalyst/dl/callbacks/scheduler.py#L10) is doing the `lr_scheduler` step\n- etc.\n\n---\nThe `order` parameter is required so that the callbacks for scheduler are not called before optimizer, and callbacks for metrics are not called before for loss.\n\n```python\nclass Callback:\n    def __init__(self, order: int):\n        \"\"\"\n        For order see ``CallbackOrder`` class\n        \"\"\"\n        self.order = order\n```\nFormally it can be any integer, but Catalyst provides enum with standard [CallbackOrder values](https://github.com/catalyst-team/catalyst/blob/b1d71998e8dad7604a3eb3ff0279fb275b8ae7e2/catalyst/dl/core/callback.py#L13).\n\n```python\nclass CallbackOrder(IntFlag):\n    Unknown = -100\n    Internal = 0  # some of the callbacks that need to be executed first\n    Criterion = 20  # for any criterion callbacks\n    Optimizer = 40  # for optimizer\n    Scheduler = 60  # for lr_scheduler\n    Metric = 80  # for metric calculations\n    External = 100  # for logs / checkpoints etc\n    Other = 200  # everything else that needs to be executed at the end\n```\n\n---\nLet us have the task of preserving the predictions of the model. To do this, we can create a callback, subscribe to the event `on_batch_end` and take the logits from the state. Then, add a scalar to tensorboard from the state.\n\n```python\nfrom catalyst.dl.core import Callback\n\nclass MyCallback(Callback):\n  # override \n  def on_batch_end(self, state: RunnerState):\n        # every train loader\n        if not state.need_backward:\n          return\n        \n        model_prediction = state.output[\"logits\"]\n        max_class = model_prediction.sigmoid().argmax()\n        \n        tensorboard = state.loggers[\"tensorboard\"].loggers[state.loader_name]\n        tensorboard.add_scalar(\"max_class\", max_class)\n```\n\n---\nUsually, to calculate metrics it is enough to implement your callback, inherited from `catalyst.dl.core.MetricCallback`, which takes `prefix` on which it will save the metric in state and `metric_fn` - a function that [calculates the metric](https://github.com/catalyst-team/catalyst/blob/b1d71998e8dad7604a3eb3ff0279fb275b8ae7e2/catalyst/dl/core/callback.py#L100).\n```python\noutputs = state.output[self.output_key]\ntargets = state.input[self.input_key]\nmetric = self.metric_fn(outputs, targets, **self.metric_params)\n```\n\n---\nA [specific callback](https://github.com/catalyst-team/catalyst/blob/master/catalyst/dl/core/callback.py#L147) `catalyst.dl.core.LoggerCallback` is also implemented for loggers. Its feature is only that on `on_\u003cevent\u003e_start` it is executed before all other callbacks, and on `on_\u003cevent\u003e_end` and `on_exception` after all of them.\n\n## Catalyst-info #4. Ecosystem\ncatalyst-version: `19.10` date: `2019-10-06`\n\nHi, everybody! Today we'll tell you about the Catalyst ecosystem, namely MLComp, Reaction, and Safitty\n\n![image 4.1](./pics/4/1.png)\n\n----------\n\n### Let's start with [MLComp](https://github.com/catalyst-team/mlcomp).\n\nIn an ecosystem of Catalyst, MLComp acts as an framework for creating complex DAGs for training/validation/inference and even submitting results on Kaggle!\nAll this is wrapped in a beautiful UI.\n\n![image 4.1](./pics/4/2.png)\n\nYou can do a lot of things through this UI, for example:\n\n- [Grid search](https://catalyst-team.github.io/mlcomp/grid_search.html). You can simply change some parameters and go through the grid ([example](https://github.com/catalyst-team/mlcomp/blob/master/examples/digit-recognizer/grid.yml))\n- Trace models in [automatic mode](https://github.com/catalyst-team/mlcomp/blob/master/examples/digit-recognizer/all.yml#L20)\n- Train models [through the distributed mode](https://github.com/catalyst-team/mlcomp/blob/master/examples/digit-recognizer/train-distr-stage.yml#L7) through the catalysts with any number of stages\n\nConfigurations for MLComp are specified in YAML\n\n![image 4.1](./pics/4/3.png)\n\nWhen executing a DAG, it can be stopped at any time and then continued, the weights will be taken directly from the Catalyst logs.\n\nAs an executor, you can specify the Submit on Kaggle and then, after the infer, the [predictions will be automatically uploaded](https://github.com/catalyst-team/mlcomp/blob/master/mlcomp/worker/executors/kaggle.py#L61).\n\n\n----------\n\n### [Safitty](https://github.com/catalyst-team/safitty)\n\nA small addition to the Catalyst is Safitty, a mini library for reading YAML/JSON configures in a uniform format.\n\n```python\nimport safitty\n\n# Reading from a file\nconfig = safitty.load(\"/path/to/config.yml\")\n\n# File recording\nsafitty.save(config, \"/path/to/config.json\")\n```\n\nAnd wrapping nested structures in a convenient readable format.\n\n```python\ngrayscale = safitty.get(config, \"reader\", \"params\", \"grayscale\")\n\n# much more readable than a regular Python\ngrayscale = config.get(\"reader\", {}).get(\"params\", {}).get(\"grayscale\")\n```\n\nAnd it helps to get values safely, including from arrays (safe in this case - without exceptions)\n\n```yaml\npaths:\n  some_key:\n    - first: \"value\"\n    - second: \"value\"\n    - third:\n      - 0\n      - 1\n      - 2\n      - 3\n  images: important/path/to/images/\n```\n\n```python\nvalue = safitty.get(config, \"paths\", \"some_key\", 1, \"third\", 3)\nprint(value) # 3\n\nvalue = safitty.get(config, \"paths\", \"some_key\", 109, \"third\", 3)\nprint(value) # None\n```\n\nThrough the properties of a normal Python we would get exception\n```python\nconfig[\"paths\"][\"some_key\"][109][\"third\"][3]\n---------------------------------------------\nIndexError Traceback (most recent call last)\n\u003cipython-input-21-bbd29787aaba\u003e in \u003cmodule\u003e\n----\u003e 1 config[\"paths\"][\"jsons\"][5][\"third\"][3]\n\nIndexError: list index out of range\n```\n\n----------\n\n### [Reaction](https://github.com/catalyst-team/reaction). The youngest project from Catalyst-team\n\nReaction was created as a framework for serving Catalyst models in production.\n\nWith only a couple of hundred lines of code inside, Reaction allows you to run your models via [API](https://github.com/catalyst-team/reaction/blob/master/example/web.py#L55).\nAll you need to do is describe the model and how it will [predict the requests](https://github.com/catalyst-team/reaction/blob/master/example/services.py#L26). Everything else is handled by Reaction.\n\nThe service configuration is [described in YAML](https://github.com/catalyst-team/reaction/blob/master/example/docker-compose.yml).\n\nIt already has:\n\n- Asyncs\n- Queues on RabbitMQ\n- Docker\n- Serialization/deserialization of any Python class\n- Predicts of the model, via telegram-bot\n\nIn the near future:\n\n- Handler support (you write a handler and your queries started to be logged, sent to the database, drawn on the client's chart, etc.)\n- Wrapper for starting the service by one command `catalyst-serve run --config \u003cpath\u003e`\n\n## Catalyst-info #3. Runners\ncatalyst-version: `19.09.4` date: `2019-09-20`\n\nHi, everybody! This is Catalyst-Team and the new issue of Catalyst-info #3.\nToday we will talk about an important framework concept - [Runner](https://github.com/catalyst-team/catalyst/blob/master/catalyst/dl/core/runner.py).\n\n---\n\nThere are two classes at the head of Catalyst.DL philosophy:\n\n- `Experiment` is a class that contains information about the experiment - a model, a criterion, an optimizer, a scheduler and their hyperparameters. It also contains information about the data and the columns used. In general, the Experiment knows what to run. It is very important and we will talk about it next time.\n- `Runner` is a class that knows how to run an experiment. It contains all the logic of how to run the experiment, stages (another distinctive feature of Catalyst), epoch and batches.\n\n---\n\nRunner's overall concept:\n\n```python\nfor stage in experiment.stages:\n    for epoch in stage.epochs:\n        for loader in epoch.loaders:\n            for batch_in in loader:\n                batch_out = runner.forward(batch_in)\n                metrics = metrics_fn(batch_in, batch_out)\n                optimize_fn(metrics)\n```\n\nRunner has only one abstract method - `forward`, which is responsible for the logic of processing incoming data by the model.\n\n---\n\nRunner uses the `RunnerState` [class](https://github.com/catalyst-team/catalyst/blob/master/catalyst/dl/core/state.py#L15) to communicate with Callbacks.\n\nIt records the current Runner parameters. For example, `batch_in` and `batch_out` , `metrics` and many others.\n\n---\n\nIn addition, if you look at the classification and segmentation tasks, you can see a lot in common.  For example, only Experiment will be different for such tasks, not Runner. For this purpose, `SupervisedRunner` [appeared in Catalyst](https://github.com/catalyst-team/catalyst/blob/master/catalyst/dl/runner/supervised.py#L17).\n\nSpecialized for these tasks, it additionally implements methods `train `, `infer ` and `predict_loader `. The basic purpose - to give additional syntactic sugar for faster and more convenient R\u0026D. Suitable both for work in Notebook API, and in Config API.\n\n---\n\nAdditionally, for integration with Weights \u0026 Biases, there are realizations `WandbRunner ` and `SupervisedWandbRunner `. They do the same thing, but additionally log all the information on the wandb.app, which is very convenient if you have a lot of experiments.\n\n---\n\nAnd finally, we're working on [GANRunner](https://github.com/catalyst-team/catalyst/pull/365) now.\n\nThat will bring everyone's favorite GANs to Catalyst.\nLet's [make GAN reproducible](catalyst-team/catalyst#365) once again!\n\n\n## Catalyst-info #2. Tracing with Torch.Jit\ncatalyst-version: `19.08.6` date: `2019-08-27`\n\nHey, everybody! This is the Catalyst-info :tada: part two!\n\nToday's post grew out of the question is any method to trace a Catalyst checkpoint with [torch.jit](https://pytorch.org/docs/stable/jit.html).\n\n**What's it for?**\n\nTraceability of Pytorch models allows you to speed up the model inference and allows you to run it not only with Python, but also with C++. It becomes like a binary file, without any code requirements – one step from research to production.\n\nAdditionally it can reduce the size of the Catalyst-checkpoint, removing all but the model.\n\n before tracing\n![image 1](./pics/2/1.png)\n\n after tracing\n![image 2](./pics/2/2.png)\n\n---\n\n**How do you get the checkpoint in Catalyst?**\n\nTo do this, there is a [command](https://github.com/catalyst-team/catalyst/blob/master/catalyst/dl/scripts/trace.py) `catalyst-dl trace \u003clogdir\u003e`\n\nFor example...\n```bash\ncatalyst-dl trace /path/to/logs\n```\n---\nFor model's tracing, Catalyst uses the same code that was dumped during experiment, so that you can always recreate your model, even if the code in the production has already changed – reproducibility first :+1: \n\n---\nYou are free to choose which of the checkpoints you want to trace (default is `best`) by the argument `--checkpoint` or, shortly, `-c`\n```bash\ncatalyst-dl trace /path/to/logs -c last\n# or\ncatalyst-dl trace /path/to/logs --checkpoint stage1.1\n```\n\nIn this case the output will look like this:\n![image 3](./pics/2/3.png)\n\n---\n\nThe `forward` method is executed by default, but this can be changed by selecting the necessary method in the `--method` argument, for example, our model has `inference` method:\n\n```bash\ncatalyst-dl trace /path/to/logs --method inference\n# or\ncatalyst-dl trace /path/to/logs -m inference\n```\n\n---\nBy default, traced models are saved in `logdir/trace`, but you can change it using one of the flags:\n1. `--out-dir` changes the directory in which the model is saved, but the name of the model is generated by Catalyst, for example `--out-dir /path/to/output/`\n2. `--out-model` indicates the path to a new file, for example `--out-model /path/to/output/traced-model-1.pth`\n\n---\n**How do I download the model after training?**\n\nOnce we've traced the model, it can be loaded into the python as\n```python\nmodel = torch.jit.load(path)\n```\nand in C++.\n```cpp\nmodule = torch::jit::load(path);\n```\n\n---\nFrom interesting facts, in a format \"and also ...\": it is possible to trace a model not only in `eval` mode, but also in `train` + in addition to specify that we need to accumulate gradients. To change the mode to `train`:\n```bash\ncatalyst-dl trace /path/to/logs --mode train\n```\n\nTo indicate that we need gradients\n```bash\ncatalyst-dl trace /path/to/logs --with-grad\n```\nThese flags can be combined\n\n\n\n## Catalyst-info #1. Segmentation models\ncatalyst-version: `19.08.6` date: `2019-08-22`\n\n### Hello, everyone!\n\nAfter the release of Catalyst in February it has a lot of new features, which, unfortunately, not everyone still knows about. Finally, we came up with an idea to post a random fact about catalyst every. So, the first release of catalyst-info!\n\n---\n\nIn Catalyst we all have implemented our favorite Unet's: \n`Unet`, `Linknet`, `FPNUnet`, `PSPnet` and their brothers with resnet-encoders \n`ResnetUnet`, `ResnetLinknet`, `ResnetFPNUnet`, `ResnetPSPnet`. \nAny `Resnet` model can be fitted with any pre-trained encoder (resnet18, resnet34, resnet50, resnet101, resnet152)\n\nUsage\n```python\nfrom catalyst.contrib.models.segmentation import ResnetUnet # or any other\nmodel = ResnetUnet(arch=\"resnet34\", pretrained=True)\n```\nIt's easy to load up a `state_dict`\n```python\nmodel = ResnetUnet(arch=\"resnet34\", pretrained=False, encoder_params=dict(state_dict=\"/model/path/resnet34-5c106cde.pth\")\n```\n---\n\n[Link to the model's code.](https://github.com/catalyst-team/catalyst/tree/master/catalyst/contrib/models/segmentation)\n\nAll models have a common general structure `encoder-bridge-decoder-head`, \neach of this part can be adjusted separately or even replaced by their own modules!\n```python\n# In the UnetMetaSpec class\ndef forward(self, x: torch.Tensor) -\u003e torch.Tensor:\n    encoder_features: List[torch.Tensor] = self.encoder(x)\n    bridge_features: List[torch.Tensor] = self.bridge(encoder_features)\n    decoder_features: List[torch.Tensor] = self.decoder(bridge_features)\n    output: torch.Tensor = self.head(decoder_features)\n    return output\n```\n\nTo bolt your model as an encoder for segmentation, you need to inherit it from \n`catalyst.contrib.models.segmentation.encoder.core.EncoderSpec` ([Code](https://github.com/catalyst-team/catalyst/blob/master/catalyst/contrib/models/segmentation/encoder/core.py#L11)).\n\n---\n\nWhen creating your own block (for any `encoder/bridge/decoder/head`) using the [function](https://github.com/catalyst-team/catalyst/blob/master/catalyst/contrib/models/segmentation/blocks/core.py#L10) `_get_block` \nyou can specify the `complexity` parameter, which will create a sequence of [complexity times by](https://github.com/catalyst-team/catalyst/blob/master/catalyst/contrib/models/segmentation/blocks/core.py#L34) `Conv2d + BN + activation`\n\n---\n\nThe Upsample part can be specified [either by interpolation or by convolution](https://github.com/catalyst-team/catalyst/blob/febcb66ade07b231348fd8e19614bdd37d548125/catalyst/contrib/models/segmentation/head/unet.py#L18).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcatalyst-team%2Fcatalyst-info","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcatalyst-team%2Fcatalyst-info","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcatalyst-team%2Fcatalyst-info/lists"}