Skip to content

Instantly share code, notes, and snippets.

View giangnguyen2412's full-sized avatar
🎯
Focusing

Giang Nguyen giangnguyen2412

🎯
Focusing
View GitHub Profile

Using FFCV to faster your training speed on ImageNet

Installation

Install ffcv and create a new environment

Follow the install instructions from the authors. This will creat a new virtual environment using conda. If you get error:

CondaHTTPError: HTTP 403 FORBIDDEN for url https://conda.anaconda.org/pytorch/win-64/pytorch-cpu-1.1.0-py3.7_cpu_1.tar.bz2

when installing pytorch for the ffcv environment, try to run:

# Create definitions for CUB-200 (CUB200 category definition - CUB200 class definition)
# All .txt files can be found here: https://www.kaggle.com/datasets/veeralakrishna/200-bird-species-with-11788-images?resource=download&select=CUB_200_2011.tgz
import re
import numpy as np
import pickle
# Read the class ID for each image. We have 11788 images, each image has a class ID from 1->200
img2class_file = 'image_class_labels.txt'
input_f = open(img2class_file)
img2class_dict = {}
@giangnguyen2412
giangnguyen2412 / SHAP_DeepExplainer_Imagenet.py
Created September 30, 2020 06:40
SHAP Deep Explainer with ImageNet datas
import glob
# load the model
model = models.vgg16(pretrained=True).eval().to(device)
# Get the prediction for the input image
test_image_paths = glob.glob('/home/dexter/Downloads/Exp1/Exp1-1 100/*.*')
test_images = list(map(lambda x: Image.open(x), test_image_paths))
test_inputs = [Compose([Resize((224,224)), ToTensor(), image_net_preprocessing])(x).unsqueeze(0) for x in test_images] # add 1 dim for batch
test_inputs = [i.to(device) for i in test_inputs]
@giangnguyen2412
giangnguyen2412 / pretrained_PT_to_TF.py
Created September 25, 2020 04:32
Convert pretrained Resnet50 model from Pytorch to Tensorflow using ONNX
## Run this on python CLI
import torch
import torchvision
torch.set_num_threads(1)
from torchvision.models import *
from visualisation.core.utils import device, image_net_postprocessing
from torch import nn
Index: src/main/java/org/alicebot/ab/AIMLProcessor.java
===================================================================
--- src/main/java/org/alicebot/ab/AIMLProcessor.java (revision 100)
+++ src/main/java/org/alicebot/ab/AIMLProcessor.java (working copy)
@@ -18,6 +18,8 @@
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
@giangnguyen2412
giangnguyen2412 / math_operation.c
Created May 16, 2018 09:50
sine and cosine function implementation in C using Taylor series
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int compare_float(double f1, double f2)
{
double precision = 0.00000000000000000001;
if ((f1 - precision) < f2)
{
return -1;