Skip to content

Commit f1531c7

Browse files
Merge pull request #69 from MATLAB-Community-Toolboxes-at-INCF/import_fixing
Import fixing
2 parents 2e73357 + a2c907f commit f1531c7

File tree

9 files changed

+61
-9
lines changed

9 files changed

+61
-9
lines changed

Diff for: +deepinterp/+internal/openTensorFlowNetwork.m

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function net = openTensorFlowNetwork(tensorFlowZipFile, namespaceName)
2+
% OPENTENSORFLOWNETWORK - open a TensorFlow network zip file
3+
%
4+
% NET = OPENTENSORFLOWNETWORK(TENSORFLOWZIPFILE, NAMESPACENAME)
5+
%
6+
% Open a network from a saved TensorFlow network zip file.
7+
%
8+
% The ZIP file should have a directory with subdirectories "assets",
9+
% "variables" and files "keras_metadata.pb" and "saved_model.pb".
10+
%
11+
% NAMESPACENAME is the namespace to be used to import the network.
12+
%
13+
% The namespace is created in the directory:
14+
% [DEEP_INTERPOLATION_ROOT filesep 'preTrainedModels' filesep 'TensorFlowNetworks']
15+
%
16+
%
17+
18+
tfnet_path = fullfile(deepinterp.toolboxpath,'pretrainedModels','TensorFlowNetworks');
19+
20+
output_files = unzip(tensorFlowZipFile,tfnet_path);
21+
modelFolder = fileparts(output_files{1});
22+
net_namespace = namespaceName;
23+
currDir = pwd;
24+
25+
did_it_fail = false;
26+
27+
try,
28+
cd(tfnet_path);
29+
net = importNetworkFromTensorFlow(modelFolder,Namespace=namespaceName);
30+
catch,
31+
did_it_fail = true;
32+
end;
33+
34+
cd(currDir);
35+
36+
if did_it_fail,
37+
error(lasterr);
38+
end;

Diff for: +deepinterp/Net.m

+8-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
% Create a new deepinterp.Net object according to instructions.
2222
% COMMAND can be any of the following:
2323
%
24-
% 'New' : create a new network (under development)
25-
% 'KerasFile' : open and import a Keras file
26-
% 'Pretrained' : Open a pretrained model in DeepInterpolation
24+
% 'New' : create a new network (under development)
25+
% 'KerasFile' : open and import a Keras file
26+
% 'TensorFlowZip' : open a TensorFlow zip file
27+
% 'Pretrained' : Open a pretrained model in DeepInterpolation
2728
%
2829
% The function also accepts additional arguments as name/value pairs:
2930
% --------------------------------------------------------------------
@@ -49,8 +50,9 @@
4950
% |-------------------------|----------------------------------------|
5051
%
5152
% Examples:
52-
% n1 = deepinterp.net('Pretrained','model','TP-Ai93-450');
53+
% n1 = deepinterp.Net('Pretrained','model','TP-Ai93-450');
5354
% n2 = deepinterp.Net('KerasFile','file','myKerasFile.H5');
55+
% n3 = deepinterp.Net('TensorFlowZip','file','myTFFile.zip','model','ModelABC');
5456
%
5557
arguments
5658
command (1,:) char {mustBeTextScalar}
@@ -73,6 +75,8 @@
7375
error(['NEW option still under development.']);
7476
case 'kerasfile',
7577
obj.network=deepinterp.internal.importKerasMAE(options.file);
78+
case 'tensorflowzip',
79+
obj.network=deepinterp.internal.openTensorFlowNetwork(options.file,matlab.lang.makeValidName(options.model));
7680
case 'pretrained',
7781
[modelfilename, modelparams] = deepinterp.internal.getPretrainedModelFilename(options.model);
7882
obj = deepinterp.Net(modelparams.format,'file',modelfilename,...

Diff for: +deepinterp/setup.m

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function setup()
1111
addpath(tbd);
1212
addpath(fullfile(tbd, "sampleData"))
1313
addpath(fullfile(tbd, "pretrainedModels"))
14+
addpath(fullfile(tbd, "pretrainedModels","TensorFlowNetworks"))
1415
addpath(fullfile(tbd, "examples"))
1516

1617

Diff for: examples/other/tiny_ophys_inference_detailed.mlx

452 KB
Binary file not shown.

Diff for: examples/tiny_ophys_inference.mlx

-327 KB
Binary file not shown.

Diff for: interop/.gitkeep

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Diff for: interop/save_model_tf.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#The following snippet is executed in Python 3.9 with TensorFlow 2.10. Currently, the import functionality in MATLAB support upto TF 2.10.
2+
#The command to install TensorFlow 2.10 is:
3+
#pip install tensorflow==2.10
4+
5+
import tensorflow as tf
6+
model = tf.keras.models.load_model('2019_09_11_23_32_unet_single_1024_mean_absolute_error_Ai93-0450.h5')
7+
model.save('TF_2019_09_11_23_32_unet_single_1024_mean_absolute_error_Ai93-0450', save_format='tf')
8+

Diff for: pretrainedModels/TensorFlowNetworks/.tensorflow

Whitespace-only changes.

Diff for: pretrainedModels/pretrained.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[
22
{
33
"name":"TP-Ai93-450",
4-
"filename":"2019_09_11_23_32_unet_single_1024_mean_absolute_error_Ai93-0450.h5",
5-
"url":"https://wds-matlab-community-toolboxes.s3.amazonaws.com/DeepInterpolation-MATLAB/Trained_models/ophys/2019_09_11_23_32_unet_single_1024_mean_absolute_error_Ai93-0450.h5",
4+
"filename":"",
5+
"url":"https://wds-matlab-community-toolboxes.s3.amazonaws.com/DeepInterpolation-MATLAB/Trained_models/ophys/TF_2019_09_11_23_32_unet_single_1024_mean_absolute_error_Ai93-0450.zip",
66
"dim":[512,512],
77
"pre":30,
88
"post":30,
99
"omit":1,
1010
"type":"two-photon",
11-
"format": "KerasFile",
11+
"format": "TensorFlowZip",
1212
"license": "https://github.com/MATLAB-Community-Toolboxes-at-INCF/DeepInterpolation-MATLAB/blob/main/LICENSE",
1313
"parameters":
1414
{
@@ -27,13 +27,13 @@
2727
{
2828
"name":"TP-Ai148",
2929
"filename":"",
30-
"url":"https://wds-matlab-community-toolboxes.s3.amazonaws.com/DeepInterpolation-MATLAB/Trained_models/ophys/2019_09_11_23_32_unet_single_1024_mean_absolute_error_Ai148-0450.h5",
30+
"url":"https://wds-matlab-community-toolboxes.s3.amazonaws.com/DeepInterpolation-MATLAB/Trained_models/ophys/2019_09_11_23_32_unet_single_1024_mean_absolute_error_Ai148-0450.zip",
3131
"dim":[512,512],
3232
"pre":30,
3333
"post":30,
3434
"omit":1,
3535
"type":"two-photon",
36-
"format": "KerasFile",
36+
"format": "TensorFlowZip",
3737
"license": "https://github.com/MATLAB-Community-Toolboxes-at-INCF/DeepInterpolation-MATLAB/blob/main/LICENSE",
3838
"parameters":
3939
{

0 commit comments

Comments
 (0)