Skip to main content

utils & misc 4 mlm8s

Project description

mlm8s

miscellaneous for machine-learning in TensorFlow

Imports:

from mlm8s import ListedPaths, paths2labels, strings2onehot, paths2label_dicts, map_via_dict
from mlm8s import GeneratorDataset, HyperModel, connect
from mlm8s import standardize, normalize, stretch, rotate_deg, flatten, correlate
from mlm8s import create_meshgrid, span_polar_basis
from mlm8s import group_unique
from mlm8s import print_plot_play

Labels from Paths:

from mlm8s import ListedPaths, paths2label_dicts, map_via_dict

### read PATH2DATA and (onehot-)encode by file-containing folder:

paths = ListedPaths(PATH2DATA)*'ogg'
label_dict = paths2label_dicts(paths(), seperators=['/', '.'], indices=[-2, 0])
labels = map_via_dict(paths2labels(paths()), label_dict)

Class - GeneratorDataset:

Enables changing results of tf.random* -calls, from within the generator of tf.data.Dataset.from_generator*.

kwargs = dict()
kwargs['paths'] = paths
kwargs['seperators'] = ['/', '.']
kwargs['indices'] = [-2, 0]

### Feature-Engineering with generator, that can use random variables!!
def engineer_features(paths):
    # use data in path to engineer features
    features = tf.random.uniform(shape=[32, 256, 256, 4])
    return features

kwargs['engineer_features'] = engineer_features

### Creating Features & Labels:
def generate_from_paths(batch_size=1024, **kwargs):
    paths = kwargs['paths']
    seperators = kwargs['seperators']
    indices = kwargs['indices']
    engineer_features = kwargs['engineer_features']
    rdm_paths = paths.get_rdm(batch_size)
    features = engineer_features(rdm_paths)
    labels = paths2labels(rdm_paths, seperators, indices)
    labels = map_via_dict(labels, label_dict)
    return features, labels

### Creating tf.data.Dataset, that can generate an infinite number of random batches
###                           from 'generate_from_paths'.
ds = GeneratorDataset(generate_from_paths, batch_size=128, epochs=16, **kwargs)()

for batch in ds.take(1):
    x, y = batch
    print(x.shape, y.shape)

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

mlm8s-1.0.0.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

mlm8s-1.0.0-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

Details for the file mlm8s-1.0.0.tar.gz.

File metadata

  • Download URL: mlm8s-1.0.0.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.11.0 Linux/5.15.0-1034-azure

File hashes

Hashes for mlm8s-1.0.0.tar.gz
Algorithm Hash digest
SHA256 212f8f9fce79ca05ab406c37b9ae479bf3e121ad25935c1c4243aa3a2c0c48da
MD5 8620f0abd835ddaf33a256ab81ccb380
BLAKE2b-256 cef0c5bc011b3fb61629c71c5f4d56fb26f9edbac6d84fe0eb9faf60c843afa7

See more details on using hashes here.

File details

Details for the file mlm8s-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mlm8s-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 27.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.11.0 Linux/5.15.0-1034-azure

File hashes

Hashes for mlm8s-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ede39fbc0cf452e7e26131475a2c09f64fabc6d3be22ca4536f281dbeff8d0d
MD5 22b539a46f4822f11126f5658ef74ea9
BLAKE2b-256 a6428179a132ca1d74ff118d81b9c41dfb67ca65594cbee5836365ac2ce18016

See more details on using hashes here.

Supported by

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