Skip to main content

Deep Learning module for Dafne

Project description

Sets of classes and interfaces for the definition of deep learning models. The framework is conceived to be extensible and serializable, in order to provide models that can be stored and/or sent through the network.

Interfaces.py

Set of abstract classes that describe models and model providers.

DeepLearningClass

The rationale behind this is that an algorithm not only depends on the model, but might require some preprocessing steps (reformatting, normalization) before the application of the model itself. The interface is also "incremental-learning-oriented" as it provides abstract methods for the calculation and integration of deltas. The class provides operator override for the calculation of deltas (D = A-B) and call override for the apply method. An instance of DeepLearningClass should be able to simply provide the expected result when called with the appropriate input data (in form of dict). The most common data for our case will be:

  • Input: {'image': 2D image, 'resolution': Sequence with pixel sizes}
  • Output: for Classifiers: str, for Segmenters: dict[str: image] where str is the label and the image is a 2D numpy array containing the mask corresponding to the string.

ModelProvider

This is an abstract class that is intended to encapsulate the logic of model load/transfer. It will have two subclasses, LocalModelProvider and RemoteModelProvider. In both cases, the method load_model of this class accepts a description of the requested model and will return an instance of DeepLearningClass. In principle, LocalModelProvider will be used on the server, and RemoteModelProvider on the client.

DynamicDLModel

Concrete implementation of a DeepLearningClass which provides flexibility and serialization. This class delegates the important methods of the model implementation to top-level functions that are passed at the construction time. These functions can be easily serialized with the dill library. Constructor:

    def __init__(self, model_id, # a unique ID to avoid mixing different models
             init_model_function, # inits the model. Accepts no parameters and returns the model
             apply_model_function, # function that applies the model. Has the object, and image, and a sequence containing resolutions as parameters
             weights_to_model_function = default_keras_weights_to_model_function, # put model weights inside the model.
             model_to_weights_function = default_keras_model_to_weights_function, # get the weights from the model in a pickable format
             calc_delta_function = default_keras_delta_function, # calculate the weight delta
             apply_delta_function = default_keras_apply_delta_function, # apply a weight delta
             incremental_learn_function = None, # function to perform an incremental learning step
             weights = None): # initial weights

This allows the implementation of a very generic deep learning algorithm which includes the preprocessing steps in a way that can be serialized and defined at runtime, so if we want to change the model, we don't need to change the code of the client or server, as the implementation is self-contained within the model. The class provides the methods dump(file_descriptor) and str = dumps() to serialize and the static methods Load(file_descriptor) and Loads(str) to deserialize. Default functions for loading/setting keras weights and calculating deltas from keras models (which provide a get_weights(), set_weights() interface with lists of numpy arrays) are currently provided. Important note when defining the functions: in order for them to be serializable, they must be completely self-contained. That is, all imports should happen inside the functions and all the external function call should be implemented as nested functions. Common algorithms (such as padorcut.py which pads or cuts an image to fit it to a specific matrix size) should be placed in the repository.

Project details


Download files

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

Source Distribution

dafne-dl-1.2a2.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

dafne_dl-1.2a2-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

Details for the file dafne-dl-1.2a2.tar.gz.

File metadata

  • Download URL: dafne-dl-1.2a2.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.5

File hashes

Hashes for dafne-dl-1.2a2.tar.gz
Algorithm Hash digest
SHA256 8110899834610722d51059f86773ea43f593c20ac1b9097070328708f9acffef
MD5 c4590db4aec992fa2cb3731582be542b
BLAKE2b-256 72efc3d2e5745f54785e6d66cdf847cac99ba38d56f600a233073bdf24d64a09

See more details on using hashes here.

File details

Details for the file dafne_dl-1.2a2-py3-none-any.whl.

File metadata

  • Download URL: dafne_dl-1.2a2-py3-none-any.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.5

File hashes

Hashes for dafne_dl-1.2a2-py3-none-any.whl
Algorithm Hash digest
SHA256 bcfa8b29cb3343908c93af519ce71e477f76637209ab0639136f34229df55f40
MD5 faf49d54178e176fb84af1246f3cf9c7
BLAKE2b-256 eb742330a4e76e072aa908dfbf61eb419711a723620684a49552ed6b6b4983c9

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