Skip to content

Commit

Permalink
Merge pull request #69 from MATLAB-Community-Toolboxes-at-INCF/import…
Browse files Browse the repository at this point in the history
…_fixing

Import fixing
  • Loading branch information
stevevanhooser authored Sep 17, 2024
2 parents 2e73357 + a2c907f commit f1531c7
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 9 deletions.
38 changes: 38 additions & 0 deletions +deepinterp/+internal/openTensorFlowNetwork.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function net = openTensorFlowNetwork(tensorFlowZipFile, namespaceName)
% OPENTENSORFLOWNETWORK - open a TensorFlow network zip file
%
% NET = OPENTENSORFLOWNETWORK(TENSORFLOWZIPFILE, NAMESPACENAME)
%
% Open a network from a saved TensorFlow network zip file.
%
% The ZIP file should have a directory with subdirectories "assets",
% "variables" and files "keras_metadata.pb" and "saved_model.pb".
%
% NAMESPACENAME is the namespace to be used to import the network.
%
% The namespace is created in the directory:
% [DEEP_INTERPOLATION_ROOT filesep 'preTrainedModels' filesep 'TensorFlowNetworks']
%
%

tfnet_path = fullfile(deepinterp.toolboxpath,'pretrainedModels','TensorFlowNetworks');

output_files = unzip(tensorFlowZipFile,tfnet_path);
modelFolder = fileparts(output_files{1});
net_namespace = namespaceName;
currDir = pwd;

did_it_fail = false;

try,
cd(tfnet_path);
net = importNetworkFromTensorFlow(modelFolder,Namespace=namespaceName);
catch,
did_it_fail = true;
end;

cd(currDir);

if did_it_fail,
error(lasterr);
end;
12 changes: 8 additions & 4 deletions +deepinterp/Net.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
% Create a new deepinterp.Net object according to instructions.
% COMMAND can be any of the following:
%
% 'New' : create a new network (under development)
% 'KerasFile' : open and import a Keras file
% 'Pretrained' : Open a pretrained model in DeepInterpolation
% 'New' : create a new network (under development)
% 'KerasFile' : open and import a Keras file
% 'TensorFlowZip' : open a TensorFlow zip file
% 'Pretrained' : Open a pretrained model in DeepInterpolation
%
% The function also accepts additional arguments as name/value pairs:
% --------------------------------------------------------------------
Expand All @@ -49,8 +50,9 @@
% |-------------------------|----------------------------------------|
%
% Examples:
% n1 = deepinterp.net('Pretrained','model','TP-Ai93-450');
% n1 = deepinterp.Net('Pretrained','model','TP-Ai93-450');
% n2 = deepinterp.Net('KerasFile','file','myKerasFile.H5');
% n3 = deepinterp.Net('TensorFlowZip','file','myTFFile.zip','model','ModelABC');
%
arguments
command (1,:) char {mustBeTextScalar}
Expand All @@ -73,6 +75,8 @@
error(['NEW option still under development.']);
case 'kerasfile',
obj.network=deepinterp.internal.importKerasMAE(options.file);
case 'tensorflowzip',
obj.network=deepinterp.internal.openTensorFlowNetwork(options.file,matlab.lang.makeValidName(options.model));
case 'pretrained',
[modelfilename, modelparams] = deepinterp.internal.getPretrainedModelFilename(options.model);
obj = deepinterp.Net(modelparams.format,'file',modelfilename,...
Expand Down
1 change: 1 addition & 0 deletions +deepinterp/setup.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function setup()
addpath(tbd);
addpath(fullfile(tbd, "sampleData"))
addpath(fullfile(tbd, "pretrainedModels"))
addpath(fullfile(tbd, "pretrainedModels","TensorFlowNetworks"))
addpath(fullfile(tbd, "examples"))


Binary file modified examples/other/tiny_ophys_inference_detailed.mlx
Binary file not shown.
Binary file modified examples/tiny_ophys_inference.mlx
Binary file not shown.
1 change: 1 addition & 0 deletions interop/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

8 changes: 8 additions & 0 deletions interop/save_model_tf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#The following snippet is executed in Python 3.9 with TensorFlow 2.10. Currently, the import functionality in MATLAB support upto TF 2.10.
#The command to install TensorFlow 2.10 is:
#pip install tensorflow==2.10

import tensorflow as tf
model = tf.keras.models.load_model('2019_09_11_23_32_unet_single_1024_mean_absolute_error_Ai93-0450.h5')
model.save('TF_2019_09_11_23_32_unet_single_1024_mean_absolute_error_Ai93-0450', save_format='tf')

Empty file.
10 changes: 5 additions & 5 deletions pretrainedModels/pretrained.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[
{
"name":"TP-Ai93-450",
"filename":"2019_09_11_23_32_unet_single_1024_mean_absolute_error_Ai93-0450.h5",
"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",
"filename":"",
"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",
"dim":[512,512],
"pre":30,
"post":30,
"omit":1,
"type":"two-photon",
"format": "KerasFile",
"format": "TensorFlowZip",
"license": "https://github.com/MATLAB-Community-Toolboxes-at-INCF/DeepInterpolation-MATLAB/blob/main/LICENSE",
"parameters":
{
Expand All @@ -27,13 +27,13 @@
{
"name":"TP-Ai148",
"filename":"",
"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",
"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",
"dim":[512,512],
"pre":30,
"post":30,
"omit":1,
"type":"two-photon",
"format": "KerasFile",
"format": "TensorFlowZip",
"license": "https://github.com/MATLAB-Community-Toolboxes-at-INCF/DeepInterpolation-MATLAB/blob/main/LICENSE",
"parameters":
{
Expand Down

0 comments on commit f1531c7

Please sign in to comment.