Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit 06f1c76

Browse files
authored
Merge pull request #61 from husthyc/master
[iOS] Update the Hello World example using Lite interpreter
2 parents f2b9aa1 + e57b5b7 commit 06f1c76

File tree

5 files changed

+5
-6
lines changed

5 files changed

+5
-6
lines changed

HelloWorld/HelloWorld/HelloWorld/TorchBridge/TorchModule.mm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#import "TorchModule.h"
2-
#import <LibTorch/LibTorch.h>
2+
#import <Libtorch-Lite/Libtorch-Lite.h>
33

44
@implementation TorchModule {
55
@protected
6-
torch::jit::script::Module _impl;
6+
torch::jit::mobile::Module _impl;
77
}
88

99
- (nullable instancetype)initWithFileAtPath:(NSString*)filePath {
1010
self = [super init];
1111
if (self) {
1212
try {
13-
_impl = torch::jit::load(filePath.UTF8String);
14-
_impl.eval();
13+
_impl = torch::jit::_load_for_mobile(filePath.UTF8String);
1514
} catch (const std::exception& exception) {
1615
NSLog(@"%s", exception.what());
1716
return nil;
18.1 KB
Binary file not shown.

HelloWorld/HelloWorld/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

22
platform :ios, '12.0'
33
target 'HelloWorld' do
4-
pod 'LibTorch', '~> 1.9.0'
4+
pod 'LibTorch-Lite', '~> 1.9.0'
55
end

HelloWorld/model.pt

-13.3 MB
Binary file not shown.

HelloWorld/trace_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
example = torch.rand(1, 3, 224, 224)
88
traced_script_module = torch.jit.trace(model, example)
99
torchscript_model_optimized = optimize_for_mobile(traced_script_module)
10-
torchscript_model_optimized.save("HelloWorld/HelloWorld/model/model.pt")
10+
torchscript_model_optimized._save_for_lite_interpreter("HelloWorld/HelloWorld/model/model.pt")

0 commit comments

Comments
 (0)