Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / model_load_util.py
Last active December 11, 2022 22:43
Load Python 3 PyTorch Networks in Python 2 for ROS deployment
import sys
import argparse
import torch
def load_model_txt(model, path):
print('Loading...')
data_dict = {}
fin = open(path, 'r')
i = 0
odd = 1
@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 / builder.sh
Created August 1, 2017 00:17
rebuild and relaunch scripts for C++ ROS projects
#!/bin/sh
WATCH_DIRS=(~/catkin_ws/src/ros-project/src/perception/src ~/catkin_ws/src/ros-project/src/perception/include/perception)
inotifywait -m ${WATCH_DIRS[@]} -e close_write |
while read path action file; do
if [[ "$file" =~ .*cpp$ ]] || [[ "$file" =~ .*h$ ]]; then
echo "$file modified, rebuilding..."
if catkin --force-color build | grep "succeeded!"; then
rosnode kill process_cloud_main
@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