Skip to content

Instantly share code, notes, and snippets.

View leemengtw's full-sized avatar
🤖
I write random stuffs about AI/ML/DS @ leemeng.tw (in Chinese)

Meng Lee leemengtw

🤖
I write random stuffs about AI/ML/DS @ leemeng.tw (in Chinese)
View GitHub Profile
df.columns = pd.MultiIndex.from_product([['Emergency'], ['全体', 'D+E', 'C', 'B', 'A']])
@leemengtw
leemengtw / create_multiindex_dataframe.py
Last active November 13, 2017 08:35
index用tuple表示
dic = {('A', 'a'): [1, 2, 3, 4, 5],
('A', 'b'): [6, 7, 8, 9, 1],
('B', 'a'): [2, 3, 4, 5, 6],
('B', 'b'): [7, 8, 9, 1, 2]}
pd.DataFrame(dic)
for i in range(ord('a'), ord('z')+1):
print(chr(i))
@leemengtw
leemengtw / keras_CNN_model_template.py
Last active December 21, 2017 01:21
Keras建立CNN model的template(基本五步驟: Define model ->Create model instance -> Compile the model -> Fit/Train -> Evaluate/Test)
import keras.backend as K
K.set_image_data_format('channels_last')
def Model(input_shape):
# Define the input placeholder as a tensor with shape input_shape. Think of this as your input image!
X_input = Input(input_shape)
# Zero-Padding: pads the border of X_input with zeroes
X = ZeroPadding2D((3, 3))(X_input)
from pymongo import MongoClient
db_setting = ["user_name","password","ip_address","db_name"]
client = MongoClient("mongodb://{}:{}@{}/{}?authMechanism=SCRAM-SHA-1".format(*db_setting))
db = client["db_name"]
db['COLLECTION_NAME'].find().count()
X, Y = create_placeholders(n_H0, n_W0, n_C0, n_y)
parameters = initialize_parameters()
Z3 = forward_propagation(X, parameters)
with tf.Session() as sess:
# Run the initialization
sess.run(init)
@leemengtw
leemengtw / check_internet_is_available.py
Last active December 21, 2017 01:20
檢查目前能不能連上internet
try:
import httplib
except:
import http.client as httplib
def have_internet():
conn = httplib.HTTPConnection("www.google.com", timeout=5)
try:
conn.request("HEAD", "/")
conn.close()
@leemengtw
leemengtw / install_selenium_in_conda
Last active December 21, 2017 01:19
在conda安裝selenium
conda install -c conda-forge selenium
conda install -c conda-forge imageio
References:
- https://anaconda.org/conda-forge/selenium
- https://stackoverflow.com/questions/46137219/how-to-install-selenium-in-a-conda-environment
@leemengtw
leemengtw / README.md
Last active December 21, 2017 01:18
建立兩層conv layers + 1 FC Network(使用tf.contrib.layers裡頭的方便api, flatten Conv layer, 並建立FC;使用max pooling)

1.2 - Forward propagation

In TensorFlow, there are built-in functions that carry out the convolution steps for you.

  • tf.nn.conv2d(X,W1, strides = [1,s,s,1], padding = 'SAME'): given an input $X$ and a group of filters $W1$, this function convolves $W1$'s filters on X. The third input ([1,f,f,1]) represents the strides for each dimension of the input (m, n_H_prev, n_W_prev, n_C_prev). You can read the full documentation here

  • tf.nn.max_pool(A, ksize = [1,f,f,1], strides = [1,s,s,1], padding = 'SAME'): given an input A, this function uses a window of size (f, f) and strides of size (s, s) to carry out max pooling over each window. You can read the full documentation here

  • tf.nn.relu(Z1): computes the elementwise ReLU of Z1 (which can be any shape). You can read the full documentation here.

@leemengtw
leemengtw / install_pil
Last active December 21, 2017 01:18
在conda環境要安裝PIL使用pip
pip install pillow
References
- https://github.com/rouseguy/DeepLearning-Image/issues/1