Skip to content

Instantly share code, notes, and snippets.

View xylcbd's full-sized avatar
🎯
Focusing

xylcbd xylcbd

🎯
Focusing
View GitHub Profile
@xylcbd
xylcbd / dl_optimizer.py
Created March 1, 2017 09:58
visualise optimizer for neural network
#coding:utf-8
import numpy as np
import matplotlib.pyplot as plt
import math
def f(x):
return x[0] * x[0] + 50 * x[1] * x[1]
def g(x):
return np.array([2 * x[0], 100 * x[1]])
#pragma once
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
#include "dirent.h"
std::string replace_all(const std::string& str, const std::string& from, const std::string& to) {
std::string result_str = str;
size_t start_pos = 0;
static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
static inline bool is_base64(unsigned char c) {
return (isalnum(c) || (c == '+') || (c == '/'));
}
#coding: utf-8
#demo of beam search for seq2seq model
import numpy as np
import random
vocab = {
0: 'a',
1: 'b',
2: 'c',
3: 'd',
@xylcbd
xylcbd / giflib_to_opencv.cpp
Created August 17, 2017 08:47
load gif to opencv mat, using giflib & opencv
//std headers
#include <fstream>
#include <iostream>
//lib headers
#include <gif_lib.h>
#define USING_NEW_GIF_LIB defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
cv::Mat imread_gif(const std::string& filename, const int flags)
{
std::ifstream stream(filename, std::ios::in | std::ios::binary);
@xylcbd
xylcbd / cr_ar.py
Last active January 6, 2021 05:52
calc cr & ar, for ocr benchmark.
def custom_min(data):
assert len(data) >= 1
if len(data) <= 0:
return data,0
min_idx = 0
min_data = data[min_idx]
for i,item in enumerate(data):
if item < min_data:
min_data = item
min_idx = i
std::string local_to_utf8(const std::string& src)
{
#if _WIN32
int len = MultiByteToWideChar(CP_ACP, 0, src.c_str(), -1, NULL, 0);
wchar_t* wszUTF16 = new wchar_t[len+1];
memset(wszUTF16, 0, len+1);
MultiByteToWideChar(CP_ACP, 0, src.c_str(), -1, wszUTF16, len);
len = WideCharToMultiByte(CP_UTF8, 0, wszUTF16, -1, NULL, 0, NULL, NULL);
char* szUTF8 = new char[len + 1];
memset(szUTF8, 0, len + 1);
static std::ostream& operator<<(std::ostream& os, const std::vector<int>& data)
{
for (size_t i = 0; i < data.size();i++)
{
os << data[i];
if (i < (int)data.size() - 1)
{
os << ", ";
}
}
static int split(std::vector<int>& data, const int beg, const int end)
{
if (beg >= end || end <= 0)
{
return -1;
}
int idx = beg;
const int base = data[end - 1];
for (int i = beg; i < end; i++)
{
#include <chrono>
#include <string>
#include <iostream>
struct profiler
{
std::string name;
std::chrono::high_resolution_clock::time_point p;
profiler(std::string const &n) :
name(n), p(std::chrono::high_resolution_clock::now()) { }