Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EfficientNetV2 and SqueezeNet #4

Merged
merged 4 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ models/**/*.onnx filter=lfs diff=lfs merge=lfs -text
models/deeplab_v3_mobilenetv3_segmentation.onnx filter=lfs diff=lfs merge=lfs -text
models/fasterrcnn_resnet50_fpn_detector.onnx filter=lfs diff=lfs merge=lfs -text
models/mobilenetv3small-classifier.onnx filter=lfs diff=lfs merge=lfs -text
models/efficientnet_v2_s_classifier.onnx filter=lfs diff=lfs merge=lfs -text
models/efficientnet_v2_m_classifier.onnx filter=lfs diff=lfs merge=lfs -text
models/efficientnet_v2_l_classifier.onnx filter=lfs diff=lfs merge=lfs -text
models/squeezenet1_1_classifier.onnx filter=lfs diff=lfs merge=lfs -text
models/ssdlite320_mobilenetv3_detector.onnx filter=lfs diff=lfs merge=lfs -text
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The package can be installed by adding `ex_vision` to your list of dependencies
```elixir
def deps do
[
{:ex_vision, "~> 0.1.0"}
{:ex_vision, "~> 0.2.0"}
]
end
```
Expand All @@ -78,10 +78,10 @@ In order to compile, ExVision **requires Rust and Cargo** to be installed on you
We have identified a set of models that we would like to support.
If the model that you would like to use is missing, feel free to open the issue, express interest in an existing one or contribute the model directly.

- [ ] Classification
- [x] Classification
- [x] MobileNetV3 Small
- [ ] EfficientNetV2
- [ ] SqueezeNet
- [x] EfficientNetV2
- [x] SqueezeNet
- [x] Object detection
- [x] SSDLite320 - MobileNetV3 Large backbone
- [x] FasterRCNN ResNet50 FPN
Expand Down
23 changes: 23 additions & 0 deletions lib/ex_vision/classification/efficientnet_v2_l.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule ExVision.Classification.EfficientNet_V2_L do
@moduledoc """
An object classifier based on EfficientNet_V2_L.
Exported from `torchvision`.
Weights from Imagenet 1k.
"""
use ExVision.Model.Definition.Ortex,
model: "efficientnet_v2_l_classifier.onnx",
categories: "priv/categories/imagenet_v2_categories.json"

use ExVision.Classification.GenericClassifier

@impl true
def preprocessing(image, _metadata) do
image
|> ExVision.Utils.resize({480, 480})
|> NxImage.normalize(
Nx.tensor([0.5, 0.5, 0.5]),
Nx.tensor([0.5, 0.5, 0.5]),
channels: :first
)
end
end
23 changes: 23 additions & 0 deletions lib/ex_vision/classification/efficientnet_v2_m.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule ExVision.Classification.EfficientNet_V2_M do
@moduledoc """
An object classifier based on EfficientNet_V2_M.
Exported from `torchvision`.
Weights from Imagenet 1k.
"""
use ExVision.Model.Definition.Ortex,
model: "efficientnet_v2_m_classifier.onnx",
categories: "priv/categories/imagenet_v2_categories.json"

use ExVision.Classification.GenericClassifier

@impl true
def preprocessing(image, _metadata) do
image
|> ExVision.Utils.resize({480, 480})
|> NxImage.normalize(
Nx.tensor([0.485, 0.456, 0.406]),
Nx.tensor([0.229, 0.224, 0.225]),
channels: :first
)
end
end
23 changes: 23 additions & 0 deletions lib/ex_vision/classification/efficientnet_v2_s.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule ExVision.Classification.EfficientNet_V2_S do
@moduledoc """
An object classifier based on EfficientNet_V2_S.
Exported from `torchvision`.
Weights from Imagenet 1k.
"""
use ExVision.Model.Definition.Ortex,
model: "efficientnet_v2_s_classifier.onnx",
categories: "priv/categories/imagenet_v2_categories.json"

use ExVision.Classification.GenericClassifier

@impl true
def preprocessing(image, _metadata) do
image
|> ExVision.Utils.resize({384, 384})
|> NxImage.normalize(
Nx.tensor([0.485, 0.456, 0.406]),
Nx.tensor([0.229, 0.224, 0.225]),
channels: :first
)
end
end
40 changes: 40 additions & 0 deletions lib/ex_vision/classification/generic_classifier.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
defmodule ExVision.Classification.GenericClassifier do
@moduledoc false

# Contains a default implementation of post processing for TorchVision classifiers
# To use: `use ExVision.Classification.GenericClassifier`

alias ExVision.Utils

alias ExVision.Types.ImageMetadata

@typep output_t() :: %{atom() => number()}

@spec postprocessing(map(), ImageMetadata.t(), [atom()]) :: output_t()
def postprocessing(%{"output" => scores}, _metadata, categories) do
scores
|> Nx.backend_transfer()
|> Nx.flatten()
|> Utils.softmax()
|> Nx.to_flat_list()
|> then(&Enum.zip(categories, &1))
|> Map.new()
end

defmacro __using__(_opts) do
quote do
@typedoc """
A type describing the output of a classification model as a mapping of category to probability.
"""
@type output_t() :: %{category_t() => number()}

@impl true
@spec postprocessing(map(), ExVision.Types.ImageMetadata.t()) :: output_t()
def postprocessing(output, metadata) do
ExVision.Classification.GenericClassifier.postprocessing(output, metadata, categories())
end

defoverridable postprocessing: 2
end
end
end
19 changes: 1 addition & 18 deletions lib/ex_vision/classification/mobilenet_v3_small.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ defmodule ExVision.Classification.MobileNetV3Small do
model: "mobilenetv3small-classifier.onnx",
categories: "priv/categories/imagenet_v2_categories.json"

require Bunch.Typespec
alias ExVision.Utils

@typedoc """
A type describing the output of MobileNetV3 classifier as a mapping of category to probability.
"""
@type output_t() :: %{category_t() => number()}
use ExVision.Classification.GenericClassifier

@impl true
def preprocessing(image, _metadata) do
Expand All @@ -26,15 +20,4 @@ defmodule ExVision.Classification.MobileNetV3Small do
channels: :first
)
end

@impl true
def postprocessing(%{"output" => scores}, _metadata) do
scores
|> Nx.backend_transfer()
|> Nx.flatten()
|> Utils.softmax()
|> Nx.to_flat_list()
|> then(&Enum.zip(categories(), &1))
|> Map.new()
end
end
23 changes: 23 additions & 0 deletions lib/ex_vision/classification/squeezenet1_1.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule ExVision.Classification.SqueezeNet1_1 do
@moduledoc """
An object classifier based on SqueezeNet1_1.
Exported from `torchvision`.
Weights from Imagenet 1k.
"""
use ExVision.Model.Definition.Ortex,
model: "squeezenet1_1_classifier.onnx",
categories: "priv/categories/imagenet_v2_categories.json"

use ExVision.Classification.GenericClassifier

@impl true
def preprocessing(image, _metadata) do
image
|> ExVision.Utils.resize({224, 224})
|> NxImage.normalize(
Nx.tensor([0.485, 0.456, 0.406]),
Nx.tensor([0.229, 0.224, 0.225]),
channels: :first
)
end
end
6 changes: 5 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule ExVision.Mixfile do
use Mix.Project

@version "0.1.0"
@version "0.2.0"
@github_url "https://github.com/membraneframework-labs/ex_vision/"

def project do
Expand Down Expand Up @@ -94,6 +94,10 @@ defmodule ExVision.Mixfile do
groups_for_modules: [
Models: [
ExVision.Classification.MobileNetV3Small,
ExVision.Classification.EfficientNet_V2_S,
ExVision.Classification.EfficientNet_V2_M,
ExVision.Classification.EfficientNet_V2_L,
ExVision.Classification.SqueezeNet1_1,
ExVision.Segmentation.DeepLabV3_MobileNetV3,
ExVision.Detection.Ssdlite320_MobileNetv3,
ExVision.Detection.FasterRCNN_ResNet50_FPN
Expand Down
8 changes: 4 additions & 4 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
"axon": {:hex, :axon, "0.6.1", "1d042fdba1c1b4413a3d65800524feebd1bc8ed218f8cdefe7a97510c3f427f3", [:mix], [{:kino, "~> 0.7", [hex: :kino, repo: "hexpm", optional: true]}, {:kino_vega_lite, "~> 0.1.7", [hex: :kino_vega_lite, repo: "hexpm", optional: true]}, {:nx, "~> 0.6.0 or ~> 0.7.0", [hex: :nx, repo: "hexpm", optional: false]}, {:polaris, "~> 0.1", [hex: :polaris, repo: "hexpm", optional: false]}, {:table_rex, "~> 3.1.1", [hex: :table_rex, repo: "hexpm", optional: true]}], "hexpm", "d6b0ae2f0dd284f6bf702edcab71e790d6c01ca502dd06c4070836554f5a48e1"},
"bunch": {:hex, :bunch, "1.6.1", "5393d827a64d5f846092703441ea50e65bc09f37fd8e320878f13e63d410aec7", [:mix], [], "hexpm", "286cc3add551628b30605efbe2fca4e38cc1bea89bcd0a1a7226920b3364fe4a"},
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"castore": {:hex, :castore, "1.0.6", "ffc42f110ebfdafab0ea159cd43d31365fa0af0ce4a02ecebf1707ae619ee727", [:mix], [], "hexpm", "374c6e7ca752296be3d6780a6d5b922854ffcc74123da90f2f328996b962d33a"},
"castore": {:hex, :castore, "1.0.7", "b651241514e5f6956028147fe6637f7ac13802537e895a724f90bf3e36ddd1dd", [:mix], [], "hexpm", "da7785a4b0d2a021cd1292a60875a784b6caef71e76bf4917bdee1f390455cf5"},
"cc_precompiler": {:hex, :cc_precompiler, "0.1.10", "47c9c08d8869cf09b41da36538f62bc1abd3e19e41701c2cea2675b53c704258", [:mix], [{:elixir_make, "~> 0.7", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "f6e046254e53cd6b41c6bacd70ae728011aa82b2742a80d6e2214855c6e06b22"},
"coerce": {:hex, :coerce, "1.0.1", "211c27386315dc2894ac11bc1f413a0e38505d808153367bd5c6e75a4003d096", [:mix], [], "hexpm", "b44a691700f7a1a15b4b7e2ff1fa30bebd669929ac8aa43cffe9e2f8bf051cf1"},
"complex": {:hex, :complex, "0.5.0", "af2d2331ff6170b61bb738695e481b27a66780e18763e066ee2cd863d0b1dd92", [:mix], [], "hexpm", "2683bd3c184466cfb94fad74cbfddfaa94b860e27ad4ca1bffe3bff169d91ef1"},
"credo": {:hex, :credo, "1.7.5", "643213503b1c766ec0496d828c90c424471ea54da77c8a168c725686377b9545", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "f799e9b5cd1891577d8c773d245668aa74a2fcd15eb277f51a0131690ebfb3fd"},
"dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"},
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
"elixir_make": {:hex, :elixir_make, "0.8.3", "d38d7ee1578d722d89b4d452a3e36bcfdc644c618f0d063b874661876e708683", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.0", [hex: :certifi, repo: "hexpm", optional: true]}], "hexpm", "5c99a18571a756d4af7a4d89ca75c28ac899e6103af6f223982f09ce44942cc9"},
"elixir_make": {:hex, :elixir_make, "0.8.4", "4960a03ce79081dee8fe119d80ad372c4e7badb84c493cc75983f9d3bc8bde0f", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.0", [hex: :certifi, repo: "hexpm", optional: true]}], "hexpm", "6e7f1d619b5f61dfabd0a20aa268e575572b542ac31723293a4c1a567d5ef040"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"evision": {:hex, :evision, "0.1.38", "f8b23ad685c3ebd70969a3457027b5c74b5bc8dc51588661c516098c3240b92d", [:make, :mix, :rebar3], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.7", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:kino, "~> 0.11", [hex: :kino, repo: "hexpm", optional: true]}, {:nx, "~> 0.4", [hex: :nx, repo: "hexpm", optional: false]}, {:progress_bar, "~> 2.0 or ~> 3.0", [hex: :progress_bar, repo: "hexpm", optional: true]}], "hexpm", "f9302547d76c5e4ad7022ffdc76be13e33c990fdd67ad2af203f24ab5d3aee20"},
"ex_doc": {:hex, :ex_doc, "0.32.1", "21e40f939515373bcdc9cffe65f3b3543f05015ac6c3d01d991874129d173420", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "5142c9db521f106d61ff33250f779807ed2a88620e472ac95dc7d59c380113da"},
"exla": {:hex, :exla, "0.7.1", "790493288cf4441abed98df0c4e98da15a2e3a7fa27cd2a1f74ec0693952c579", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:nx, "~> 0.7.1", [hex: :nx, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:xla, "~> 0.6.0", [hex: :xla, repo: "hexpm", optional: false]}], "hexpm", "ec9c1698a9a17b859d79f9b3c1d75c370335580cdd0353db9c2017f86155e2ec"},
"exla": {:hex, :exla, "0.7.2", "8ac573093df8e5e6b36845beeb3f5a0ea92b05082bf2fa4678f80170cfc887f6", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:nx, "~> 0.7.1", [hex: :nx, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:xla, "~> 0.6.0", [hex: :xla, repo: "hexpm", optional: false]}], "hexpm", "d061ea87858415e5585cbd4b7bdae5489000339519a2c6a7f51eb0defd73b588"},
"file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"},
"finch": {:hex, :finch, "0.18.0", "944ac7d34d0bd2ac8998f79f7a811b21d87d911e77a786bc5810adb75632ada4", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6 or ~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "69f5045b042e531e53edc2574f15e25e735b522c37e2ddb766e15b979e03aa65"},
"hpax": {:hex, :hpax, "0.2.0", "5a58219adcb75977b2edce5eb22051de9362f08236220c9e859a47111c194ff5", [:mix], [], "hexpm", "bea06558cdae85bed075e6c036993d43cd54d447f76d8190a8db0dc5893fa2f1"},
Expand All @@ -31,7 +31,7 @@
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"},
"numbers": {:hex, :numbers, "5.2.4", "f123d5bb7f6acc366f8f445e10a32bd403c8469bdbce8ce049e1f0972b607080", [:mix], [{:coerce, "~> 1.0", [hex: :coerce, repo: "hexpm", optional: false]}, {:decimal, "~> 1.9 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "eeccf5c61d5f4922198395bf87a465b6f980b8b862dd22d28198c5e6fab38582"},
"nx": {:hex, :nx, "0.7.1", "5f6376e3d18408116e8a84b8f4ac851fb07dfe61764a5410ebf0b5dcb69c1b7e", [:mix], [{:complex, "~> 0.5", [hex: :complex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e3ddd6a3f2a9bac79c67b3933368c25bb5ec814a883fc68aba8fd8a236751777"},
"nx": {:hex, :nx, "0.7.2", "7f6f6584585e49ffbf81769e7ccc2d01c5639074e399c1f94adc2b509869673e", [:mix], [{:complex, "~> 0.5", [hex: :complex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e2c0680066eec5af8b8ef00c99e9bf40a0d08d8b2bbba77f59f801ec54a3f90e"},
"nx_image": {:hex, :nx_image, "0.1.2", "0c6e3453c1dc30fc80c723a54861204304cebc8a89ed3b806b972c73ee5d119d", [:mix], [{:nx, "~> 0.4", [hex: :nx, repo: "hexpm", optional: false]}], "hexpm", "9161863c42405ddccb6dbbbeae078ad23e30201509cc804b3b3a7c9e98764b81"},
"ortex": {:hex, :ortex, "0.1.9", "a9b14552ef6058961a3e300f973a51887328a13c2ffa6f2cad1b0785f9c7e73c", [:mix], [{:nx, "~> 0.6", [hex: :nx, repo: "hexpm", optional: false]}, {:rustler, "~> 0.29.0", [hex: :rustler, repo: "hexpm", optional: false]}], "hexpm", "5201b9aa8e22a86f3a04e819266bfd1c5a8194f0c51f917c1d0cffe8bdbb76d8"},
"phoenix_html": {:hex, :phoenix_html, "4.1.1", "4c064fd3873d12ebb1388425a8f2a19348cef56e7289e1998e2d2fa758aa982e", [:mix], [], "hexpm", "f2f2df5a72bc9a2f510b21497fd7d2b86d932ec0598f0210fed4114adc546c6f"},
Expand Down
80 changes: 80 additions & 0 deletions python/exports/classification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import argparse
from torchvision.transforms.functional import to_tensor, resize
import torch
import json
from pathlib import Path
from PIL import Image


def export(model_builder, Model_Weights, input_shape):
base_dir = Path(f"models/classification/{model_builder.__name__}")
base_dir.mkdir(parents=True, exist_ok=True)

model_file = base_dir / "model.onnx"
categories_file = base_dir / "categories.json"

weights = Model_Weights.DEFAULT
model = model_builder(weights=weights)
model.eval()

categories = [x.lower().replace(" ", "_")
for x in weights.meta["categories"]]
transforms = weights.transforms()

with open(categories_file, "w") as f:
json.dump(categories, f)

onnx_input = to_tensor(Image.open("test/assets/cat.jpg")).unsqueeze(0)
onnx_input = resize(onnx_input, input_shape)
onnx_input = transforms(onnx_input)

torch.onnx.export(
model,
onnx_input,
str(model_file),
verbose=False,
input_names=["input"],
output_names=["output"],
dynamic_axes={
"input": {0: "batch_size"},
"output": {0: "batch_size"}
},
export_params=True,
)

expected_output: torch.Tensor = model(onnx_input)
expected_output = expected_output.softmax(dim=1)

result = dict(zip(categories, expected_output[0].tolist()))

file = Path(
f"test/assets/results/classification/{model_builder.__name__}.json"
)
file.parent.mkdir(exist_ok=True, parents=True)

with file.open("w") as f:
json.dump(result, f)


parser = argparse.ArgumentParser()
parser.add_argument("model")
args = parser.parse_args()

match(args.model):
case "mobilenet_v3_small":
from torchvision.models import mobilenet_v3_small, MobileNet_V3_Small_Weights
export(mobilenet_v3_small, MobileNet_V3_Small_Weights, [224, 224])
case "efficientnet_v2_s":
from torchvision.models import efficientnet_v2_s, EfficientNet_V2_S_Weights
export(efficientnet_v2_s, EfficientNet_V2_S_Weights, [384, 384])
case "efficientnet_v2_m":
from torchvision.models import efficientnet_v2_m, EfficientNet_V2_M_Weights
export(efficientnet_v2_m, EfficientNet_V2_M_Weights, [480, 480])
case "efficientnet_v2_l":
from torchvision.models import efficientnet_v2_l, EfficientNet_V2_L_Weights
export(efficientnet_v2_l, EfficientNet_V2_L_Weights, [480, 480])
case "squeezenet1_1":
from torchvision.models import squeezenet1_1, SqueezeNet1_1_Weights
export(squeezenet1_1, SqueezeNet1_1_Weights, [224, 224])
case _:
print("Model not found")
Loading
Loading