LogoLogo
  • Tensorleap
  • Examples
    • Semantic Segmentation
    • Image Analysis
    • Sentiment Analysis
    • MNIST Project Walkthrough
    • IMDB Project Walkthrough
  • Quickstart using CLI
  • Guides
    • Full Guides
      • MNIST Guide
        • Dataset Integration
        • Model Integration
        • Model Perception Analysis
        • Advanced Metrics
      • IMDB Guide
        • Dataset Integration
        • Model Integration
        • Model Perception Analysis
        • Advanced Metrics
    • Integration Script
      • Preprocess Function
      • Input Encoder
      • Ground Truth Encoder
      • Metadata Function
      • Visualizer Function
      • Prediction
      • Custom Metrics
      • Custom Loss Function
      • Custom Layers
      • Unlabeled Data
      • Examples
        • CelebA Object Detection (YoloV7)
        • Wikipedia Toxicity (using Tensorflow Datasets)
        • Confusion Matrix
        • CelebA Classification (using GCS)
  • Platform
    • Resources Management
    • Project
    • Dataset
    • Secret Manager
    • Network
      • Dataset Node
      • Layers
      • Loss and Optimizer
      • Visualizers
      • Import Model
      • Metrics
    • Evaluate / Train Model
    • Metrics Dashboard
    • Versions
    • Issues
    • Tests
    • Analysis
      • helpers
        • detection
          • YOLO
    • Team management
    • Insights
  • API
    • code_loader
      • leap_binder
        • add_custom_metric
        • set_preprocess
        • set_unlabeled_data_preprocess
        • set_input
        • set_ground_truth
        • set_metadata
        • add_prediction
        • add_custom_loss
        • set_visualizer
      • enums
        • DatasetMetadataType
        • LeapDataType
      • datasetclasses
        • PreprocessResponse
      • visualizer_classes
        • LeapImage
        • LeapImageWithBBox
        • LeapGraph
        • LeapText
        • LeapHorizontalBar
        • LeapImageMask
        • LeapTextMask
  • Tips & Tricks
    • Import External Code
  • Legal
    • Terms of Use
    • Privacy Policy
Powered by GitBook
On this page
  • Formats
  • Import Model using UI

Was this helpful?

  1. Platform
  2. Network

Import Model

Learn how to import models into Tensorleap

PreviousVisualizersNextMetrics

Last updated 2 years ago

Was this helpful?

Tensorleap supports importing models exported to various standard formats, including standard TensorFlow (SaveModel/H5/JSON) and PyTorch (ONNX).

Formats

JSON_TF2 - JSON format (TensorFlow 2)

The JSON format serializes the model layers, their properties and connectivity. It does not hold the state (weights) of the model.

Below is a code snippet for saving a TensorFlow model as a JSON file:

json_file = open("model.json", "w")
json_file.write(model.to_json())
json_file.close()

More info at .

H5_TF2 - H5 format (TensorFlow 2)

The h5 format serializes the model and model state (weights) as a single h5 file.

Below is a code snippet for loading an exported h5 file:

model.save('model.h5')

More info at .

ONNX format (PyTorch)

The onnx format is commonly used in PyTorch for serializing the model's layers and state (weights).

Below is a code snippet for exporting a model to an onnx file in PyTorch:

import torch
import torchvision

dummy_input = torch.randn(10, 3, 224, 224, device="cuda")
model = torchvision.models.alexnet(pretrained=True).cuda()

input_names = [ "actual_input_1" ] + [ "learned_%d" % i for i in range(16) ]
output_names = [ "output1" ]

torch.onnx.export(model, dummy_input, "alexnet.onnx", verbose=True, input_names=input_names, output_names=output_names)

SavedModel_TF2 - SaveModel serialization (TensorFlow 2)

Uses the TensorFlow 2 SaveModel to export a folder with files containing the serialized model layers and state.

Below is a code snippet to load the model from the extracted folder:

model.save('model_folder')

The serialized data is stored to a folder with this directory structure:

assets/ (folder)
variables/ (folder)
saved_model.pb

When importing the folder generated by the model.save() format from Tensorleap, the exported folder needs to be contained in a tar.gz file.

One way to do it is by using tar:

tar -zcvf model_folder.tar.gz  model_folder

Import Model using UI

To import a model:

  1. Enter the revision name and model name, and select the import file format from the list.

  2. Click and select the import file from your system.

5. Click Import.

More info at .

More info at .

On the Network view, click to open the Import Model panel.

Optional: Select a to connect to your model

If your model contains this step is mandatory. You must first add these to the dataset script and select the dataset before moving to the next step.

6. Once the import process is complete, the model is added to the view.

7. Position your cursor over the version and click , then Open Commit.

8. Back on the Network view, point the to the model's and connect it to the first layer in the network.

Once a dataset has been integrated with Tensorleap, it becomes available for use with your models. More info about Dataset Integration can be found at .

8. Add a for the network, then set it up for .

https://www.tensorflow.org/api_docs/python/tf/keras/models/model_from_json
https://www.tensorflow.org/tutorials/keras/save_and_load
https://pytorch.org/docs/stable/onnx.html
https://www.tensorflow.org/api_docs/python/tf/keras/models/save_model
Dataset
Custom Layers
Versions
Dataset
Loss and Optimizer
training
Dataset Block
Dataset Instance
Setting up the import
Importing a model and pointing its Dataset Block to a dataset instance