Skip to content

Instantly share code, notes, and snippets.

View thirdwing's full-sized avatar
🏠
Working from home

Qiang Kou (KK) thirdwing

🏠
Working from home
View GitHub Profile
@sbodenstein
sbodenstein / rnn_test.lua
Created July 27, 2016 23:11
Compare Torch + MXNet cuDNN RNN API's
--
require 'cudnn'
require 'cunn'
torch.setdefaulttensortype('torch.FloatTensor')
-- Get weight dim
function checkSums(rnn, seqLength, batch, inputDim, hiddenSize, layerNum, bidirectional)
rnn:reset()
@dannguyen
dannguyen / README.md
Last active December 28, 2023 15:21
Using Python 3.x and Google Cloud Vision API to OCR scanned documents to extract structured data

Using Python 3 + Google Cloud Vision API's OCR to extract text from photos and scanned documents

Just a quickie test in Python 3 (using Requests) to see if Google Cloud Vision can be used to effectively OCR a scanned data table and preserve its structure, in the way that products such as ABBYY FineReader can OCR an image and provide Excel-ready output.

The short answer: No. While Cloud Vision provides bounding polygon coordinates in its output, it doesn't provide it at the word or region level, which would be needed to then calculate the data delimiters.

On the other hand, the OCR quality is pretty good, if you just need to identify text anywhere in an image, without regards to its physical coordinates. I've included two examples:

####### 1. A low-resolution photo of road signs

#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
void r_message(std::string text)
{
Rcpp::Function msg("message");
msg(text);
}
@romainfrancois
romainfrancois / gist:6119995
Created July 31, 2013 07:20
Two workarounds to get access to the c level connections api from c++.
#include <Rcpp.h>
// thanks to Simon for the macro magic
// problem #1: R internals uses "private" and "class" as
// member names. So a C++ compiler is confused
// when we include Connections.h
// this workaround uses the preprocessor to rename
// class as class_name and private as private_ptr
#define class class_name
#define private private_ptr
@BenLangmead
BenLangmead / DeBruijn.py
Last active September 26, 2023 15:39
Demonstration of de Bruijn graph construction and Eulerian path/cycle finding.
class DeBruijnGraph:
""" A de Bruijn multigraph built from a collection of strings.
User supplies strings and k-mer length k. Nodes of the de
Bruijn graph are k-1-mers and edges correspond to the k-mer
that joins a left k-1-mer to a right k-1-mer. """
@staticmethod
def chop(st, k):
""" Chop a string up into k mers of given length """
for i in xrange(0, len(st)-(k-1)):
@pssguy
pssguy / global.R
Last active January 21, 2018 01:25
Motion Chart of Premier League Positions by game for past 20+ seasons. Shiny app using googleVis package The data is not currently provided but to-date charts can be viewed at glimmer.rstudio.com/pssguy/eplTableMotion/
# load requisite libraries
library(shiny)
library(googleVis)
# load raw data (NB not provided)
tableByGame <- read.csv("../tableByGame.csv",stringsAsFactors=FALSE)
# to create chart need to repeat one column and get negative of league position as hack
tableByGame$game <- tableByGame$seasonGame
tableByGame$lgPos <- -tableByGame$lgPos
function writeStuff(n)
f=open("data.txt","w")
for el in 1:n
r=randi(Int32)
println(f,r)
end
close(f)
end
N = 1000_000
@jcheng5
jcheng5 / server.R
Last active June 17, 2021 18:37
Shiny example: Diamonds Explorer
library(shiny)
library(ggplot2)
function(input, output) {
dataset <- reactive({
diamonds[sample(nrow(diamonds), input$sampleSize),]
})
output$plot <- renderPlot({
@smc77
smc77 / logistic_gradient_descent.R
Created October 28, 2011 03:14
Logistic Regression with Gradient Descent
num.iterations <- 1000
# Download South African heart disease data
sa.heart <- read.table("http://www-stat.stanford.edu/~tibs/ElemStatLearn/datasets/SAheart.data", sep=",",head=T,row.names=1)
x <- sa.heart[,c("age", "ldl")]
y <- sa.heart$chd
plot(x, pch=21, bg=c("red","green")[factor(y)])
# Function to standardize input values
@tc
tc / gist:1217766
Created September 14, 2011 20:57
resize and crop using imagej -java version
package imagej;
import ij.*;
import ij.io.*;
import ij.process.*;
import java.io.*;
import javax.imageio.*;
import javax.imageio.stream.*;
import java.awt.image.BufferedImage;