Skip to content

Instantly share code, notes, and snippets.

@thomasweng15
thomasweng15 / edit_pickle.py
Last active January 9, 2023 15:21
edit a pickle
# best run in an interpreter or with a breakpoint
import pickle
fn = ''
with open(fn, 'rb') as f:
a = pickle.load(f)
# make edits
# breakpoint()
@thomasweng15
thomasweng15 / plotly_save.py
Last active September 26, 2023 23:20
3D Interactive Visualizations with Plotly
# Save html to the specified path
fig.write_html("plotly_sphere_pts.html")
# Save to wandb (call wandb.init() first)
# html = plotly.io.to_html(fig)
# wandb.log(
# {
# f"plotly_sphere_pts": wandb.Html(html),
# }
# )
@thomasweng15
thomasweng15 / visualize.py
Last active December 21, 2022 22:48
trimesh to plotly
import os
import trimesh
import plotly.graph_objects as go
import plotly.figure_factory as ff
import numpy as np
from voxelized_pointcloud_sampling import create_grid_points_from_bounds
import pickle
"""Load all meshes and inputs into the same plot to make sure everything is aligned. """
@thomasweng15
thomasweng15 / mp.py
Created December 14, 2022 20:09
Multiprocessing passing values back
import multiprocessing as mp
def process(arguments, res_q):
(i,) = arguments
res_q.put([i])
max_processes = 2
queue = mp.Queue()
@thomasweng15
thomasweng15 / settings.json
Created December 1, 2022 21:14
VSCode settings for python black
{
// https://dev.to/adamlombard/how-to-use-the-black-python-code-formatter-in-vscode-3lo0
"python.formatting.provider": "black",
"python.formatting.blackPath": "/home/exx/miniconda3/envs/gifs_cloth/bin/black",
"editor.formatOnSave": true,
}
@thomasweng15
thomasweng15 / mp.py
Last active November 21, 2022 21:10
multiprocessing with a queue and pool
// https://stackoverflow.com/questions/17241663/filling-a-queue-and-managing-multiprocessing-in-python
import time
import os
import multiprocessing as mp
from multiprocessing import Queue, Pool
the_queue = Queue()
def worker_main(queue):
print(f"{os.getpid()} working")
@thomasweng15
thomasweng15 / launch.json
Last active November 18, 2022 17:23
VSCode debugger launch.json for softgym
// Softgym Fabric Touch
{
"name": "Debug: Sawyer Cloth Env",
"type": "python",
"request": "launch",
"console": "integratedTerminal",
"cwd": "/home/exx/projects/IDM/softgym_implicit_cloth_proj",
"python": "/home/exx/miniconda3/envs/softgym-ft/bin/python",
"program": "/home/exx/projects/IDM/softgym_implicit_cloth_proj/examples/demonstrator.py",
"env": {
@thomasweng15
thomasweng15 / train.py
Created July 27, 2022 03:07
wandb with pre-emption
import os
import sys
import pytorch_lightning as pl
import pytorch_lightning.utilities.seed as seed_utils
from pytorch_lightning import loggers as pl_loggers
from pytorch_lightning.callbacks import ModelCheckpoint
import hydra
import yaml
@thomasweng15
thomasweng15 / hsv_segmenter.py
Created March 21, 2022 15:52
Segment HSV from an image rostopic using OpenCV sliders
import cv2
import rospy
import argparse
import numpy as np
import matplotlib.pyplot as plt
from cv_bridge import CvBridge
from sensor_msgs.msg import Image
class Segmenter():
def __init__(self, args):
@thomasweng15
thomasweng15 / reskin_3d_plot.py
Created February 5, 2022 06:37
3D reskin plot
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import TimedAnimation
class SubplotAnimation(TimedAnimation):
def __init__(self, num_steps=50):
fig = plt.figure()
self.ax1 = fig.add_subplot(2, 1, 1)
self.ax2 = fig.add_subplot(2, 1, 2, projection='3d')
self.ax2.set(xlim3d=(-1, 1), xlabel='X')