NumPy Any: Understanding np.any()

Ben Cook • Posted 2021-10-21

The np.any() function tests whether any element in a NumPy array evaluates to true: The input can have any shape and the data type does not have to be boolean (as long as it’s truthy). If none of the elements evaluate to true, the function returns false: Passing in a … Read more

PyTorch DataLoader Quick Start

Ben Cook • Posted 2021-10-07 • Last updated 2021-10-18

PyTorch comes with powerful data loading capabilities out of the box. But with great power comes great responsibility and that makes data loading in PyTorch a fairly advanced topic. One of the best ways to learn advanced topics is to start with the happy path. Then add complexity when you … Read more

Poetry for Package Management in Machine Learning Projects

Ben Cook • Posted 2021-07-08 • Last updated 2021-10-20

When you’re building a production machine learning system, reproducibility is a proxy for the effectiveness of your development process. But without locking all your Python dependencies, your builds are not actually repeatable. If you work in a Python project without locking long enough, you will eventually get a broken build … Read more

Development containers in VS Code: a quick start guide

Ben Cook • Posted 2021-06-29 • Last updated 2022-09-07

If you’re building production ML systems, dev containers are the killer feature of VS Code. Dev containers give you full VS Code functionality inside a Docker container. This lets you unify your dev and production environments if production is a Docker container. But even if you’re not targeting a Docker … Read more

Basic Counting in Python

Ben Cook • Posted 2021-05-14 • Last updated 2021-10-15

I love fancy machine learning algorithms as much as anyone. But sometimes, you just need to count things. And Python’s built-in data structures make this really easy. Let’s say we have a list of strings: With a list like this, you might care about a few different counts. What’s the … Read more

How to Use the PyTorch Sigmoid Operation

Ben Cook • Posted 2021-05-13 • Last updated 2021-10-14
sigmoid function

The PyTorch sigmoid function is an element-wise operation that squishes any real number into a range between 0 and 1. This is a very common activation function to use as the last layer of binary classifiers (including logistic regression) because it lets you treat model predictions like probabilities that their … Read more

TorchVision Transforms: Image Preprocessing in PyTorch

Ben Cook • Posted 2021-03-19 • Last updated 2021-10-21

TorchVision, a PyTorch computer vision package, has a great API for image pre-processing in its torchvision.transforms module. This post gives some basic usage examples, describes the API and shows you how to create and use custom image transforms.