Skip to content

Instantly share code, notes, and snippets.

View YuehChuan's full-sized avatar

YuehChuan YuehChuan

  • Taiwan
  • 17:58 (UTC +08:00)
View GitHub Profile
@YuehChuan
YuehChuan / gist:1daab7c49828d925294e4dd9eb813e42
Created October 27, 2023 00:04
nn.embedding backward grad
import torch
import torch.nn as nn
# an Embedding module containing 10 tensors of size 3
embedding = nn.Embedding(6, 3)
# a batch of 2 samples of 3 elements each
input = torch.LongTensor([[1, 2, 3],[0,2,3]])
loss=torch.sum(embedding(input))
print("embedding" )
print(embedding.weight )
@YuehChuan
YuehChuan / CMakeLists.txt
Created April 21, 2021 13:55 — forked from tdenewiler/CMakeLists.txt
ROS Synchronization Example
cmake_minimum_required(VERSION 2.8.3)
project(sync_example)
find_package(catkin REQUIRED COMPONENTS message_filters roscpp sensor_msgs)
catkin_package(
CATKIN_DEPENDS message_filters roscpp sensor_msgs
)
include_directories(${catkin_INCLUDE_DIRS})
@YuehChuan
YuehChuan / imagenet_normalization.py
Created November 10, 2020 07:29 — forked from pmeier/imagenet_normalization.py
Calculation of ImageNet z-score parameters
import argparse
import multiprocessing
from math import ceil
import torch
from torch.utils import data
from torchvision import datasets, transforms
class FiniteRandomSampler(data.Sampler):
def __init__(self, data_source, num_samples):
@YuehChuan
YuehChuan / PyTorch 入門最速傳說.ipynb
Created July 10, 2020 07:53 — forked from remorsecs/PyTorch 入門最速傳說.ipynb
本文目標是讓沒寫過 PyTorch 的讀者成為 PyTorch 新手 (?)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/bin/sh
printf "\n$(cat ascii.txt)\n"
@YuehChuan
YuehChuan / ascii.txt
Created May 31, 2020 07:15
ascii.txt
       
   .....   
   .........   
     .  ..  ....   
     .  ..  ....     
   .  .............     
   ..[
#include <stdio.h>
#include <stdlib.h>
//function pointer
typedef int (*MathMethod)(int, int);
int Mul(int a, int b) { return a*b; }
float Divide(int a, int b) { return a/b; }
int Minus(int a, int b) { return a-b; }
int Add(int a, int b) { return a+b; }
@YuehChuan
YuehChuan / ptr_test.txt
Created April 27, 2020 14:27
(parameter with reference or pointer)g++ -std=c++11 main.cpp -o main
#include <iostream>
#include <memory>
void foo( const std::shared_ptr<int> p)
{
static int x = 0;
*p = ++x;
// printf("address p %p \n",p);
// printf("value x %d \n",x );
// printf("value p %d \n",*p);
}
corleone@corleone:~$ roscore
... logging to /home/corleone/.ros/log/82647bda-509f-11ea-85b2-6cf049e820ae/roslaunch-corleone-17865.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://corleone:45267/
ros_comm version 1.14.3
corleone@corleone:~$ sudo apt install ros-melodic-desktop
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
amd64-microcode apg apport-symptoms aptdaemon-data command-not-found-data diffstat gettext gir1.2-goa-1.0 gir1.2-snapd-1 gir1.2-vte-2.91 gnome-control-center-faces gnome-online-accounts
gnome-software-common intel-microcode intltool-debian iucode-tool libapt-pkg-perl libarchive-zip-perl libcgi-fast-perl libcgi-pm-perl libclass-accessor-perl libclone-perl libcolord-gtk1
libemail-valid-perl libexporter-tiny-perl libfcgi-perl libgtop-2.0-11 libgtop2-common libio-pty-perl libio-string-perl libipc-run-perl liblist-moreutils-perl libllvm8 libnet-dns-perl
libnet-domain-tld-perl libnet-ip-perl libnss-myhostname libparse-debianchangelog-perl libperlio-gzip-perl libsodium23 libtext-levenshtein-perl libwhoopsie-preferences0 libxatracker2 libxml-libxml-perl
libxml-namespacesupport-