Skip to content

Instantly share code, notes, and snippets.

View goldsborough's full-sized avatar
🔨
Fixing things

Peter Goldsborough goldsborough

🔨
Fixing things
View GitHub Profile
#include <torch/torch.h>
#include "mnist_reader.h"
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
from __future__ import print_function
import argparse
import os
import random
import torch
import torch.nn as nn
import torch.nn.parallel
import torch.backends.cudnn as cudnn
import torch.optim as optim
import torch.utils.data
@goldsborough
goldsborough / data_loader.cpp
Created September 19, 2018 00:46
Stream/Random policy data loader
namespace torch {
namespace data {
template <typename D = torch::Tensor, typename L = torch::Tensor>
struct Example {
D data;
L label;
};
template <typename D>
@goldsborough
goldsborough / sema.cpp
Created September 20, 2018 00:30
C++ semaphore
class Semaphore {
public:
void post() {
std::lock_guard<std::mutex> lock(mutex_);
count_ += 1;
cv_.notify_one();
}
void shutdown() {
std::lock_guard<std::mutex> lock(mutex_);
- Old-style factory functions that accept a type as first argument and size as second argument have been removed. New-style factory functions accepting the size as first argument and [`TensorOptions`](https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/core/TensorOptions.h#L14) as last argument should be used instead. For example, replace your call e.g. to `at::ones(torch::CPU(at::kFloat)), {2, 3})` with `torch::ones({2, 3}, at::kCPU)`. This applies to the following functions:
- `arange`
- `empty`
- `eye`
- `full`
- `linspace`
- `logspace`
- `ones`
- `rand`
- `randint`
#include <torch/torch.h>
torch::nn::Linear model(num_features, 1);
torch::optim::SGD optimizer(model->parameters());
auto data_loader = torch::data::data_loader(dataset);
for (size_t epoch = 0; epoch < 10; ++epoch) {
for (auto batch : data_loader) {
auto prediction = model->forward(batch.data);
auto loss = loss_function(prediction, batch.target);
@goldsborough
goldsborough / download_mnist.py
Created January 8, 2019 19:26
Python script to download the MNIST dataset
from __future__ import division
from __future__ import print_function
import argparse
import gzip
import os
import sys
import urllib
try:
// Place your key bindings in this file to override the defaults
[
{
"key": "shift+backspace",
"command": "deleteRight",
"when": "textInputFocus && !editorReadonly"
},
{
"key": "alt+d",
"command": "deleteWordRight",