Skip to content

Instantly share code, notes, and snippets.

View dpoulopoulos's full-sized avatar
🏠
Working from home

Dimitris Poulopoulos dpoulopoulos

🏠
Working from home
View GitHub Profile
@dpoulopoulos
dpoulopoulos / nlsh.py
Last active June 14, 2023 11:25
OpenAI natural language shell example.
prompt = """
Input: Print the current directory
Output: pwd
Input: List files
Output: ls -l
Input: Change directory to /tmp
Output: cd /tmp
plt.figure(figsize=(10,6))
sns.kdeplot(probs_lgr, label='Logistic regression')
sns.kdeplot(preds_svc, label='SVM')
plt.title("Probability Density Plot for 2 Classifiers")
plt.show()
strategy = tf.distribute.MirroredStrategy()
BATCH_SIZE = 64
GLOBAL_BATCH_SIZE = BATCH_SIZE * strategy.num_replicas_in_sync
train_data = tf.data.Dataset(...).batch(GLOBAL_BATCH_SIZE)
with strategy.scope():
model = tf.keras.Sequential(...)
model.compile(...)
BATCH_SIZE = 64
train_data = tf.data.Dataset(...).batch(BATCH_SIZE)
model = tf.keras.Sequential(...)
model.compile(...)
model.fit(train_data, epochs=4)
class MyModel(keras.Model):
def train_step(self, data):
# Get the data batch
inputs, targets = data
# Get the model's weights
trainable_vars = self.trainable_variables
# Forward pass
with tf.GradientTape() as tape:
# Get the predictions
preds = self(inputs, training=True)
import torch
import torchvision.models as models
import torchvision.transforms as transforms
from PIL import Image
img = Image.open("test/assets/encode_jpeg/grace_hopper_517x606.jpg")
# Step 1: Load a pre-trained model.
from PIL import Image
from torchvision.prototype import models as pm
img = Image.open("test/assets/encode_jpeg/grace_hopper_517x606.jpg")
# Step 1: Load a pre-trained model.
# In this step we will load a ResNet architecture.
weights = pm.ResNet50_Weights.ImageNet1K_V1
model = pm.resnet50(weights=weights)
FROM <base.Dockerfile:tag>
# Install Tensorflow
RUN pip3 install tensorflow
# Install PyTorch
RUN pip3 install torch==1.5.1 torchvision==0.6.1
# Create and configure NB_USER user with UID=1000 and in the 'users' group
# but allow for non-initial launches of the notebook to have
# $HOME provided by the contents of a PV
ARG CUDA=10.1
ARG UBUNTU_VERSION=18.04
FROM nvidia/cuda:${CUDA}-base-ubuntu${UBUNTU_VERSION} as base
# ARCH and CUDA are specified again because the FROM directive resets ARGs
# (but their default value is retained if set previously)
ARG CUDA
ARG CUDNN=7.6.4.38-1
ARG CUDNN_MAJOR_VERSION=7
import ctypes
import pathlib
if __name__ == "__main__":
# load the lib
libname = pathlib.Path().absolute() / "libcadd.so"
c_lib = ctypes.CDLL(libname)
x, y = 6, 2.3