Skip to main content

python client for the NetsPresso

Project description

NetsPresso

Installation

To install this package, please use Python 3.8 or higher.

Install from Source:

git clone https://github.com/nota-github/netspresso-python.git
pip install -e .

Install from PyPi (Recommended):

To be updated later.

Quickstart

Login

Please enter your email and password to log in to your NetsPresso account.

from netspresso.compressor import ModelCompressor

compressor = ModelCompressor(email="YOUR_EMAIL", password="YOUR_PASSWORD")

Model

Upload

from netspresso.compressor import Task, Framework

UPLOAD_MODEL_NAME = "tensorflow_keras_mv1"
TASK = Task.IMAGE_CLASSIFICATION
FRAMEWORK = Framework.TENSORFLOW_KERAS
UPLOAD_MODEL_PATH = "./mobilenetv1.h5"
INPUT_LAYERS = [{"batch": 1, "channel": 3, "dimension": [32, 32]}]

model = compressor.upload_modfel(
    model_name=UPLOAD_MODEL_NAME,
    task=TASK,
    framework=FRAMEWORK,
    file_path=UPLOAD_MODEL_PATH,
    input_layers=INPUT_LAYERS,
)
print(f"model_id: {model.model_id}")

Get

model = compressor.get_model(model_id="UPLOADED_MODEL_ID")
print(f"model_id: {model.model_id}")

Compression

Manual

# Select Compression Method
COMPRESSION_METHOD = CompressionMethod.PR_L2.value
compression_1 = compressor.select_compression_method(
    model=model,
    compression_method=COMPRESSION_METHOD
)
print(f"compression method: {compression_1.compression_method}")
print(f"available layers: {compression_1.available_layers}")

# Set Compression Params
for available_layer in compression_1.available_layers[:5]:
    available_layer.values = [0.2]

# Compress Model
COMPRESSED_MODEL_NAME = "l2norm_manual"
OUTPUT_PATH = "./mobilenetv1_cifar100_manual.h5"
compressed_model = compressor.compress_model(
    compression=compression_1,
    model_name=COMPRESSED_MODEL_NAME,
    output_path=OUTPUT_PATH,
)
print(f"compressed model id: {compressed_model.model_id}")

Recommendation

COMPRESSED_MODEL_NAME = "recommendation_model"
COMPRESSION_METHOD = CompressionMethod.PR_L2
RECOMMENDATION_METHOD = RecommendationMethod.LAMP
RECOMMENDATION_RATIO = 0.6
OUTPUT_PATH = "./mobilenetv1_cifar100_recommendation.h5"
compressed_model = compressor.recommendation_compression(
    model=model,
    model_name=COMPRESSED_MODEL_NAME,
    compression_method=COMPRESSION_METHOD,
    recommendation_method=RECOMMENDATION_METHOD,
    recommendation_ratio=RECOMMENDATION_RATIO,
    output_path=OUTPUT_PATH,
)
print(f"compressed model id: {compressed_model.model_id}")

Automatic

AUTO_COMPRESSED_MODEL_NAME = "test_auto_compress"
OUTPUT_PATH = "./mobilenetv1_cifar100_automatic.h5"
COMPRESSION_RATIO = 0.5
compressed_model = compressor.automatic_compression(
    model=model,
    model_name=AUTO_COMPRESSED_MODEL_NAME,
    compression_ratio=COMPRESSION_RATIO,
    output_path=OUTPUT_PATH,
)
print(f"compressed model id: {compressed_model.model_id}")

Project details


Release history Release notifications | RSS feed

This version

0.1.3

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

netspresso-0.1.3-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file netspresso-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: netspresso-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for netspresso-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d477496f36d39d03fde4390965d819c2017834c72620ffefe03f90f71bfbe9ed
MD5 15345a5e56906f75aa1ca2e0ca34bd5c
BLAKE2b-256 51c5e93570de56341a5dc7a73be2c1f65bab7ad8b23409c550a28850d525412a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page