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


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.2-py3-none-any.whl (18.5 kB view hashes)

Uploaded Python 3

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