This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import torch | |
def layernorm_forward(x, gamma, beta, eps): | |
out, cache = None, None | |
M, _ = x.shape | |
x_mean = np.mean(x, axis=1).reshape(M, 1) | |
x_var = np.var(x, axis=1).reshape(M, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def batchnorm_forward(x, gamma, beta, eps): | |
N, D = x.shape | |
# step1: calculate mean | |
mu = 1./N * np.sum(x, axis=0) | |
# step2: subtract mean vector of every trainings example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import tensorflow as tf | |
from tensorflow.keras.datasets import mnist | |
from tensorflow.keras.utils import to_categorical | |
from tensorflow.keras.models import Sequential | |
from tensorflow.keras.layers import Dense, Activation, Conv2D, Flatten | |
from tensorflow.keras.optimizers import RMSprop | |
# download the mnist to the path '~/.keras/datasets/' if it is the first time to be called | |
# X shape (60,000 28x28), y shape (10,000, ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import | |
from __future__ import division | |
from __future__ import print_function | |
import argparse | |
import sys | |
from PIL import Image | |
import numpy as np | |
import tensorflow as tf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
typedef vector< vector<float>> matrix; | |
void PrintMatrix(const matrix& mat) | |
{ | |
for (int i = 0, row = mat.size(); i < row; ++i) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
using namespace std; | |
using namespace cv; | |
cv::Mat GetMask(const Mat& img) | |
{ | |
Mat ret; | |
Mat imgGray; | |
cvtColor(img, imgGray, CV_BGR2GRAY); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
sys.path.append("/opt/tf_model/research") | |
sys.path.append("/opt/tf_model/research/object_detection") | |
import os | |
import cv2 | |
import numpy as np | |
import tensorflow as tf | |
from utils import label_map_util |