Skip to content

Add Inception V4 model to examples #86

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

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions examples/models/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ python_library(
deps = [
"//caffe2:torch",
"//executorch/examples/models/inception_v3:ic3_export",
"//executorch/examples/models/inception_v4:ic4_export",
"//executorch/examples/models/mobilenet_v2:mv2_export",
"//executorch/examples/models/mobilenet_v3:mv3_export",
"//executorch/examples/models/torchvision_vit:vit_export",
Expand Down
14 changes: 14 additions & 0 deletions examples/models/inception_v4/TARGETS
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("@fbcode_macros//build_defs:python_library.bzl", "python_library")

python_library(
name = "ic4_export",
srcs = [
"__init__.py",
"export.py",
],
base_module = "executorch.examples.models.inception_v4",
deps = [
"fbsource//third-party/pypi/timm:timm",
"//caffe2:torch",
],
)
11 changes: 11 additions & 0 deletions examples/models/inception_v4/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

from .export import InceptionV4Model

__all__ = [
InceptionV4Model,
]
30 changes: 30 additions & 0 deletions examples/models/inception_v4/export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import logging

import torch
from timm.models import inception_v4

FORMAT = "[%(filename)s:%(lineno)s] %(message)s"
logging.basicConfig(format=FORMAT)


# will refactor this in a separate file.
class InceptionV4Model:
def __init__(self):
pass

@staticmethod
def get_model():
logging.info("loading inception_v4 model")
m = inception_v4(pretrained=True)
logging.info("loaded inception_v4 model")
return m

@staticmethod
def get_example_inputs():
return (torch.randn(3, 299, 299).unsqueeze(0),)
7 changes: 7 additions & 0 deletions examples/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ def gen_inception_v3_model_and_inputs() -> Tuple[torch.nn.Module, Any]:
return InceptionV3Model.get_model(), InceptionV3Model.get_example_inputs()


def gen_inception_v4_model_and_inputs() -> Tuple[torch.nn.Module, Any]:
from ..models.inception_v4 import InceptionV4Model

return InceptionV4Model.get_model(), InceptionV4Model.get_example_inputs()


MODEL_NAME_TO_MODEL = {
"mul": lambda: (MulModule(), MulModule.get_example_inputs()),
"linear": lambda: (LinearModule(), LinearModule.get_example_inputs()),
Expand All @@ -118,4 +124,5 @@ def gen_inception_v3_model_and_inputs() -> Tuple[torch.nn.Module, Any]:
"vit": gen_torchvision_vit_model_and_inputs,
"w2l": gen_wav2letter_model_and_inputs,
"ic3": gen_inception_v3_model_and_inputs,
"ic4": gen_inception_v4_model_and_inputs,
}