Skip to content

Instantly share code, notes, and snippets.

View ageron's full-sized avatar

Aurélien Geron ageron

View GitHub Profile
@ageron
ageron / drop_outputs_in_git_history.sh
Created February 23, 2022 01:59
A bash script that removes all Jupyter notebook outputs from a git repository's history
#!/bin/bash -e
echo 'Usage:
1. install git-filter-repo from https://github.com/newren/git-filter-repo
2. make a clean clone of your repository (keep a backup!)
3. cd to the repo and run this script
'
python -c 'input("Are you sure? Press Ctrl-C to cancel or Enter to continue.")'
@ageron
ageron / Issue #439.ipynb
Created September 30, 2021 23:20
HOML2 – Issue #439.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#=
This code comes mostly from the talk "JuliaCon 2019 | Multi-threading in Julia with PARTR":
https://youtu.be/HfiRnfKxI64?t=729
It is a Julia translation of this Go code:
https://github.com/thomas11/csp/blob/f2ec7c4/csp.go#765
I fixed a few errors in the Julia code:
* replaced numPrimes with n
* replaced `if m < m` with `if m < mp`
public class Vertex {
var key: String
public init(key: String) {
self.key = key
print("Creating vertex \(key)")
}
deinit {
print("Removing vertex \(key)")
}
}
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Flatten, Conv2D
from tensorflow.keras.layers import MaxPooling2D, BatchNormalization
keras.backend.clear_session()
np.random.seed(1000)
tf.random.set_seed(1000)
@ageron
ageron / custom_train_test.py
Created March 25, 2019 15:06
Test of a custom training loop
import numpy as np
import tensorflow as tf
from tensorflow import keras
model = keras.models.Sequential([keras.layers.Dense(1, input_shape=[5])])
optimizer = keras.optimizers.SGD()
def step(model, optimizer, X_batch, y_batch):
with tf.GradientTape() as tape:
y_pred = model(X_batch)
@ageron
ageron / stereogram.py
Created March 11, 2019 07:06
Converts one or more 3D images for red/blue 3D glasses into stereogram images
"""
Converts one or more 3D images for red/blue 3D glasses into stereogram images. Example:
Download:
https://www.nasa.gov/sites/default/files/styles/full_width/public/thumbnails/image/nh-ut_stereo_bluered_030619.png
Then run:
python stereogram.py nh-ut_stereo_bluered_030619.png
This will generate:
import numpy as np
from tensorflow import keras
import traceback
class ResidualBlock(keras.layers.Layer):
def __init__(self, n_layers, n_neurons, **kwargs):
super().__init__(**kwargs)
self.n_layers = n_layers
self.n_neurons = n_neurons
self.hidden = [keras.layers.Dense(n_neurons, activation="elu",
@ageron
ageron / tf2-colab.sh
Created January 21, 2019 08:21
Installs everything you need to run TF 2.0-preview on an Ubuntu 18.04 server (includes the Colab connector) - run as regular user with sudo rights
#!/bin/bash
cat <<EOF > install_cuda_10_and_nvidia_driver_384.sh
#!/bin/bash
apt-get update && apt-get install -y --no-install-recommends gnupg2 curl ca-certificates && \
curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub | apt-key add - && \
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list && \
echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list
export CUDA_VERSION=10.0.130
@ageron
ageron / list_procs.py
Created January 16, 2019 03:20
A few utility functions to list procs by name or by their command line arguments
"""
Usage:
>>> for pid, name in search_procs_by_name("python").items():
... print(pid, name)
...
11882 python3.6
47599 python3.6
51877 python3.6
51924 python3.6