2019年4月29日 星期一

CIFAR load and save to picture

import pickle as p
import numpy as np
from PIL import Image
import os

def unpickle(file):
    with open(file, 'rb') as fo:
        dict = p.load(fo, encoding='bytes')
    return dict

'''
        batch file key:
        b'batch_label'
        b'labels'
        b'data'
        b'filenames'
'''
CIFAR10PATH = "E:\\project\\python\\cifar10\\cifar-10-batches-py\\"
DATABATCH = "data_batch_"
OUTPUTFOLDER = ".\\images\\"
#E:\project\python\cifar10\cifar-10-batches-py
if __name__ == "__main__":
    for i in range(1,2):
        batchName = CIFAR10PATH + DATABATCH+str(i)
        print("batch name:"+str(batchName))
        cifar = unpickle(batchName)
        for d in range(10000):
            labelNum = cifar[b'labels'][d]
            imgData = cifar[b'data'][d]
            #remove utf-8 name with b'
            filenames = cifar[b'filenames'][d].decode("utf-8")

            #If the dimension with length 3 is the RGB axis, then you want it at the end.
            #If your array has shape (3, R, C), then np.transpose(img, (1, 2, 0))
            #will have shape (R, C, 3).
            imgData = imgData.reshape(3, 32, 32) #CIFAR default format 3 channels with RxC
            #(0, 1, 2) no change (3, R, C) ==> transpose to (1, 2, 0) => (R, C, 3)
            imgData = imgData.transpose(1, 2, 0)
            img = Image.fromarray(imgData, 'RGB')
            folderName = OUTPUTFOLDER + str(labelNum)
            if not os.path.exists(folderName):
                os.makedirs(folderName)
            img.save(folderName+"\\"+str(filenames).strip()+'.jpg')

2017年11月15日 星期三

android trace

traceView -> for app

systrace ->focus on kernel ftrace(surfaceflinger, )
https://kknews.cc/zh-tw/news/enbv3on.html
kernel -> ftrace,  app-> trace class
/tools/systrace.py

追到app問題後,也要使用traceView來協助分析

2017年9月27日 星期三

mt.exe 停止運作 MSB6006

vs2010

Property -> linker -> Manifest File -> Generate Manifest -> No(Manifest:No)

2017年9月20日 星期三

arduino avrdude upload hex file by command

Arduino Uno

avrdude -c arduino -P com4 -b 115200 -p ATMEGA328p -U flash:w:camBox.ino.hex
or
avrdude -c arduino -P com4 -b 115200 -p m328p -U flash:w:camBox.ino.hex
or
avrdude -c arduino -P com4 -b 115200 -p ATMEGA328p -U flash:w:E:\camBox.ino.hex:i


Arduino Mega

avrdude -c wiring -P com4 -b 115200 -p m2560 -U flash:w:camBox.ino.hex

avrdude -c wiring -P com4 -b 115200 -p ATmega2560 -U flash:w:E:\camBox.ino.hex:i


partno list
http://www.nongnu.org/avrdude/user-manual/avrdude_4.html

or see the avrdude.conf

2016年12月29日 星期四

步進馬達

幾相幾線?

相:最直接影響的是 精度,越多相,精度越細
兩相: 激磁後,1.8DEG

線:最直接影響就是unipolar or bi-polar, 單電流激磁,按照順序即可順轉反轉
雙電流則,電留有方向性來控制正反轉

驅動IC:ULN2003,7組達靈頓電路,可以將每組並聯使用,放大驅動電流來達到驅動基本電流的需求

2016年2月18日 星期四

adb lauch each app from android

adb shell pm list package -f
adb shell pm list package #list all package

launch each package by monkey
adb shell monkey -p ${package_name} -c android.intent.category.LAUNCHER 1;


2016年2月8日 星期一

github usage note

github 有個情境

假設要共同開發一個project ex:  http://github.com/dev.git
這時你可以fork 到你的github, 經過開發時間透過pull request,跟夥伴貢獻了不少commit

這時該如何更新最新的version到你fork的git?

first, 先建立一個upstream, 可任意命名,就稱upstream吧

git remote add upstream http://github.com/dev.git

then, fetch remote, git remote -v --可以看origin 跟 remote的 git

git fetch upstream
git checkout master

這時可以更新你的git by rebase
git rebase upstream/master
也可透過merge方式來更新git
git merge upstream/master

rebase push 到你的git
git push -f  origin master

ref:
http://stackoverflow.com/questions/7244321/how-to-update-a-github-forked-repository

開發local branch 一陣子後 commit 並merge 成 master
dev
master
git checkout dev
git commit -a
git checkout master
git merge dev

更新upstream 後,merge 到 local dev branch
git checkout master
git fetch upstream
git merge upstream/master
==> commit to your fork
git checkout dev
git merge master