TFLite
edgemark.models.platforms.TFLite.TFLite_converter
basic_convert
basic_convert(model_path)
Convert the model without any optimizations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path
|
str
|
The path to the TensorFlow model. |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
The TFLite model. |
Source code in edgemark/models/platforms/TFLite/TFLite_converter.py
175 176 177 178 179 180 181 182 183 184 185 186 187 | |
cluster
cluster(model_path, n_clusters)
Cluster the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path
|
str
|
The path to the TensorFlow model. |
required |
n_clusters
|
int
|
The number of clusters. |
required |
Returns:
| Type | Description |
|---|---|
Model
|
The clustered model. |
Source code in edgemark/models/platforms/TFLite/TFLite_converter.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
main
main(cfg_path=config_file_path, **kwargs)
Convert the TensorFlow models to TFLite models with the specified optimizations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg_path
|
str
|
The path to the configuration file. The configuration file that this path points to should contain the following keys: - model_base_dir (str): A placeholder for the model base directory. This will be populated by the target directory. - linkers_dir (str): Path to the directory where the generated models list is loaded from and the converted models list will be saved. - tf_model_path (str): Path to the TensorFlow model. - representative_data_path (str): Path to the representative data for quantization. The file should be a numpy file. - tflite_save_dir (str): Path to the directory to save the converted models and their assets. - conversion_timeout (float): The timeout for each conversion in seconds. - optimizations (list): The optimizations to apply during conversion. In each element/group, the optimizations should be separated by '+'. |
config_file_path
|
**kwargs
|
dict
|
Keyword arguments to be passed to the configuration file. |
{}
|
Returns:
| Type | Description |
|---|---|
list
|
A list of dictionaries containing the following keys for each target model: - dir (str): The directory of the target model. - flavors (list): A list of dictionaries containing the following keys for each optimization: - flavor (str): The optimization flavor. - result (str): The result of the conversion. It can be either "success" or "failed". - error (str): The error message in case of failure. - traceback (str): The traceback in case of failure. Either this or 'exception_file' will be present. - exception_file (str): The path to the exception file in case of failure. Either this or 'traceback' will be present. |
Source code in edgemark/models/platforms/TFLite/TFLite_converter.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
prune
prune(model_path, target_sparsity)
Prune the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path
|
str
|
The path to the TensorFlow model. |
required |
target_sparsity
|
float
|
The target sparsity. |
required |
Returns:
| Type | Description |
|---|---|
Model
|
The pruned model. |
Source code in edgemark/models/platforms/TFLite/TFLite_converter.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
quantize
quantize(model_path, representative_data=None, int_only=False, a16_w8=False, float16=False)
Quantize the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path
|
str
|
The path to the TensorFlow model. |
required |
representative_data
|
ndarray
|
The representative data for quantization. |
None
|
int_only
|
bool
|
Whether to force the model to use integer quantization only. |
False
|
a16_w8
|
bool
|
Whether to quantize the model to use 16-bit activations and 8-bit weights. |
False
|
float16
|
bool
|
Whether to quantize the model to use 16-bit floating point numbers. |
False
|
Returns:
| Type | Description |
|---|---|
bytes
|
The TFLite model. |
Source code in edgemark/models/platforms/TFLite/TFLite_converter.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
save_random_eqcheck_data
save_random_eqcheck_data(model_path, n_samples, save_path)
Saves a random eqcheck data as {"data_x", "data_y_pred"}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path
|
str
|
The path to the TFLite model. |
required |
n_samples
|
int
|
The number of samples to generate. |
required |
save_path
|
str
|
The npz file path to save the data. |
required |
Source code in edgemark/models/platforms/TFLite/TFLite_converter.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |