Skip to content

Instantly share code, notes, and snippets.

View alexcdot's full-sized avatar
🚀
Learning!

Alexander Cui alexcdot

🚀
Learning!
View GitHub Profile
@usamec
usamec / resumable_sampler.py
Created August 25, 2020 10:50
Resumable (and savable) random sampler for Pytorch data loader
import torch
class ResumableRandomSampler(torch.utils.data.Sampler):
r"""Samples elements randomly. If without replacement, then sample from a shuffled dataset.
If with replacement, then user can specify :attr:`num_samples` to draw.
Arguments:
data_source (Dataset): dataset to sample from
replacement (bool): samples are drawn on-demand with replacement if ``True``, default=``False``
num_samples (int): number of samples to draw, default=`len(dataset)`. This argument
is supposed to be specified only when `replacement` is ``True``.
@skyrocknroll
skyrocknroll / protobuf.sh
Created November 3, 2017 07:50
Install protobuf 3 on ubuntu 16
# Make sure you grab the latest version
curl -OL https://github.com/google/protobuf/releases/download/v3.4.0/protoc-3.4.0-linux-x86_64.zip
# Unzip
unzip protoc-3.4.0-linux-x86_64.zip -d protoc3
# Move protoc to /usr/local/bin/
sudo mv protoc3/bin/* /usr/local/bin/
# Move protoc3/include to /usr/local/include/
@jinyu121
jinyu121 / get_anchor.py
Last active March 5, 2024 02:36
YOLO2 Get Anchors
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import numpy as np
import os
import random
@somada141
somada141 / vtk_load_stl.md
Last active January 27, 2022 06:46
Load an the contents of an STL file into a vtkPolyData object with Python and VTK #python #vtk #fileIO #visualizaton #stl

Assuming we have an .stl file under filenameSTL we can load the contents of that file using the vtkSTLReader class as such:

readerSTL = vtk.vtkSTLReader()
readerSTL.SetFileName(filenameSTL)
# 'update' the reader i.e. read the .stl file
readerSTL.Update()

polydata = readerSTL.GetOutput()