2016년 12월 7일 수요일

Hough Line Theory with Python

Point is [6,1],[4,2],[1,4]

Eq is x*sin(theta) + y * cos(theta) = r

let's calculate r

--------------------------------------------------------------------

import numpy as np

def getpos(x,y,theta):
    return  x*np.sin(theta) + y * np.cos(theta)

output1 = []
output2 = []
output3 = []
for i in xrange(-90,90,20):
    output1.append(getpos(6,1,i))
    output2.append(getpos(4,2,i))
    output3.append(getpos(1,4,i))

--------------------------------------------------------------------

output1 is [6,1]
output2 is [4,2]
output3 is [1,4]

Lets Draw Graph
--------------------------------------------------------------------

import numpy as np
import matplotlib.pyplot as plt

def getpos(x,y,theta):
    return  x*np.sin(theta) + y * np.cos(theta) 

output1 = []
output2 = []
output3 = []
for i in xrange(-90,90,20):
    output1.append(getpos(6,1,i))
    output2.append(getpos(4,2,i))
    output3.append(getpos(1,4,i))
ThetaList = np.arange(-90,90,20)
print len(ThetaList)
print len(output1)
plt.plot(ThetaList,output1,ThetaList,output2,ThetaList,output3)
plt.show()

--------------------------------------------------------------------


This is Code For analysis and Save data

--------------------------------------------------------------------
import numpy as np
import matplotlib.pyplot as plt
import math

def getpos(x,y,theta):
    return  x*np.sin(theta) + y * np.cos(theta) 

output1 = []
output2 = []
output3 = []
for i in xrange(-90,90,20):
    output1.append(getpos(6,1,i))
    output2.append(getpos(4,2,i))
    output3.append(getpos(1,4,i))
ThetaList = np.arange(-90,90,20)
print len(ThetaList)
print len(output1)
plt.plot(ThetaList,output1,ThetaList,output2,ThetaList,output3)
plt.show()

AcArray1 = np.zeros((len(output1),len(ThetaList)),dtype='byte')
AcArray2 = np.zeros((len(output2),len(ThetaList)),dtype='byte')
AcArray3 = np.zeros((len(output3),len(ThetaList)),dtype='byte')

AcarrayList = [AcArray1,AcArray2,AcArray3]
OutputList = [output1,output2,output3]

for j in range(3):
    for i in range(len(ThetaList)):
        ycor = ycor1 = math.trunc(OutputList[j][i]) + 9

        if ycor < 10 and ycor > -10 and ycor != 0:
            if   ycor > 0:
                AcarrayList[j][i][ycor -1] += 1
            else:
                AcarrayList[j][i][ycor] += 1

print AcArray1
print AcArray2
print AcArray3
total = AcArray1 + AcArray2 + AcArray3
print total 
print "----"

np.savetxt("test.txt",total,fmt = '%1.0f')
    
    

--------------------------------------------------------------------



2016년 11월 21일 월요일

NN Tip

1. Batch size: Batch size is a very critical parameter when you're dealing with Recurrent Neural Networks. Plain Feed forward neural networks and Convolutional Neural Networks aren't affected much by the batch size. That being said, you can expect slightly better performance and convergence with a higher batch size. Especially if you're using a simple gradient descent algorithm like sgd. More complex algorithms like rmsprop and adam aren't affected as much by the batch size.
  1. Number of epochs: The way it's usually done in practice is you divide your training set into three parts - train, validation and test. You train on the train set and keep checking the performance on the validation set. When the validation performance stops changing, you stop training. Looking at purely the train performance is bound to make your model overfit.
  2. How to know if model is overfitting: A simple way to do this is to just observe the difference between your train error and validation error. The difference is initially quite small as your model just begins to train. Sometimes your validation performance might be better. But with increasing number of epochs your validation performance starts to lag behind and it's up to you to choose when to stop training. It's generally a sign of overfitting if your validation accuracy has peaked.
  3. Number of hidden layers: You can choose to have as many hidden layers as you want. It has been proven that deeper networks work better for image classification compared to shallow networks. There are networks with 1200 layers now (Resnet). But deeper networks lead to a few problems that need to be handled carefully. You need to choose your activation function properly. Otherwise you'll have problems with vanishing and exploding gradients. ReLu is generally a good choice for image classification. You need to make sure your model doesn't overfit. Deeper networks benefit from dropout technique. Use weight and activity regularizations. Add noise to your images to make them generalize better and find more stable optima. Use data augmentation. These are just a few tips that come to mind right now. There are a lot of other things that can be done. There isn't any fixed rule that says number of neurons need to be 2/3rd of the input size.
The easiest technique though? Use pre-trained networks like VGG-16 and Inception or Resnet. They've already been trained to optimum and will generally give you a very good out of box performance.

2016년 11월 20일 일요일

python command

>upgrade keras

--
pip install keras --upgrade
--

>upgrade package all

--
conda upgrade --all
--

>

[python] OpenCV3 or OpenCv2 check

need check version of opencv

[python] FilePath

import glob
path = os.path.join(r'D:\A_002ImageClassificationData\kaggle\fish', 'input', 'train', fld, '*.jpg')
files = glob.glob(path)




반듯이 \를 한번만 쓸거면 앞에 r을 붙인다. 

이러면 경로상의 *.jpg의 파일이 모두 리스트로 저장이 된다. (풀 경로로 )

2016년 11월 12일 토요일

2016/11/12. IronPython, Python.Net 실패

C# 과 Python 을 연동해, C#의 UI 에 파이썬 그래프등을 띄우는것은 포기

Iron Python 에서 외부 패키지 설치를 못하겠음.

- 참조 사이트 :

https://github.com/QuantConnect/Lean/wiki/IronPython

http://kechengpuzi.com/q/s29397540

2016/11/12 [Clojure] 흐름제어

2장 흐름제어까지 공부