레이블이 neural net인 게시물을 표시합니다. 모든 게시물 표시
레이블이 neural net인 게시물을 표시합니다. 모든 게시물 표시

2026년 1월 16일 금요일

인공지능에서 정규화(Normalizing)와 표준화(Standardizing)

 "Normalizing" a vector most often means dividing by a norm of the vector,
for example, to make the Euclidean length of the vector equal to one. In the NN literature, "normalizing" also often refers to rescaling by the minimum and range of the vector, to make all the elements lie between 0 and 1. 

- 정규화(Normalizing) : 데이터 혹은 벡터를 정규화 한다는 것은 벡터의 크기로 벡터를 나누어 크기(Euclidean Length)가 1이 되도록 하는 것이다. 인공지능 영역에서는 정규화 과정을 종종 모든 데이터가 0과 1 사이의 크기를 갖도록 재조정(rescaling)하는 것으로 사용된다.

"Standardizing" a vector most often means subtracting a measure of location and dividing by a measure of scale. For example, if the vector contains random values with a Gaussian distribution, you might subtract the mean and divide by the standard deviation, thereby obtaining a "standard normal" random variable with mean 0 and standard deviation 1. 

 - 표준화(Standardizing - 이거 뭐라읽어야 하나 스탠다디자이징??): 모든 벡터의 평균값을 빼고, 측정된 표준편차로 나누는 작업. 예를 들어 Gaussian 분포(distribution)을 갖는 랜덤 값을 갖는 벡터를 평균이 0이되고 표준 편차가 1이 되는 "standard normal" 랜덤 변수로 만다는 작업을 잃컫는다.

 그럼 뭘써야 하나 그때 그때 다르다. 어쨌든 써야지 만족할 만한 성능을 기대할 수 있다.

Multilayer Perceptron(흔히들 말하는 클래식 인공지능, 다층 fully-connected layer로 구성된 NN)의 경우 입력값이 0과 1 사이어야 한다. 하지만, 사실 어떠한 요구조건은 아니지만 데이터의 평균값이 0이면 좋다. 그래서 데이터가 0과 1사이의 값이 되게만 만드는 행위는 좋은 선택이 아니다.  

 그래서 학습과정 중 최적화 단계의 수치해석적 향상을 위해선 Stadardizing을 입력과 결과값 모두에 적용하는 것이 좋아 보인다. 

참고 자료:

http://www.faqs.org/faqs/ai-faq/neural-nets/part2/

 

2022년 7월 27일 수요일

인공지능+영상처리+OceanOptics USB2000+Flir Camera 를 위한 시스템 설정

# 작업 시스템

윈도우즈 11, 64bits

# 설치 소프트웨어

## Python 3.8.xx

64bit 버전으로 설치하고, 현 시점에 최신 버전은 3.10이지만, 인공지능을 위한 tensorflow가 지원하는 최신 버전인 3.9.13버전이고 Spinnaker라는 Camera 소프트웨어는 3.8.xx버전을 지원한다.

### pip(Python Install Package) 설치

설치하고 가장 먼저해야할 작은 pip(Python Install Package)를 업그레이드 하는 것이다.

PS D:\python -m pip install --upgrade pip

그럼 tensorflow를 설치할 수 있는 환경이 조성되었다.

### tensorflow 와 tensorflow-cpu 설치 

PS D:\python -m pip install tensorflow

설치된 tensorflow를 확인해보자.

PS D:\> python

Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf

2022-07-27 11:53:34.911913: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found

2022-07-27 11:53:34.912570: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

>>> quit()

CUDA 런타임 라이브러리가 없다고 에러를 발생시킨다. 그래서 cpu전용 구동할 수 있는 tensorflow-cpu를 추가 설치한다.

PS D:\> python -m pip install tensorflow-cpu

다시, 설치된 tensorflow의 버전을 확인해 보자.

PS D:\> python

Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf

>>> tf.__version__

'2.9.1'

>>> quit()

### PySide6 설치

PS D:\> python -m pip install PySide6

설치된 버전 확인한다.

PS D:\> python

Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import PySide6

>>> PySide6.__version__

'6.3.1'

>>> quit()

### OpenCV 설치

PS D:\> python -m pip install opencv-python

설치된 버전 확인한다.

PS D:\> python

Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import cv2

>>> cv2.__version__

'4.6.0'

>>> quit()

## Visual Studio Code 설치

아래의 사이트를 방문해서 해당 시스템에 알맞은 설치파일을 다운로드 받는다.

https://code.visualstudio.com/download

설치 후 PySide6 예제를 코딩하고 실행해 본다.


## FLIR 카메라를 위한 환경 설정

과거의 Point Gray사의 카메라를 사용하기 위해서 현재는 FLIR로 합병된 Spinnaker SDK를 설치해야한다.

SpinnakerSDK_FULL_2.7.0.128.x64.exe 파일을 다운로드하고 설치한다.

그리고,  Python 에서 카메라를 운용하기 위해서 spinnaker_python-2.7.0.128-cp38-cp38-win_amd64.zip 파일도 다운로드하고, 다음의 명령어로 설치한다.

PS D:\> python -m pip install .\spinnaker_python-2.7.0.128-cp38-cp38-win_amd64.whl

그리고 설치확인한다.


import os
import PySpin
import sys

if __name__ == '__main__':
    # Retrieve singleton reference to system object
    system = PySpin.System.GetInstance()

    # Get current library version
    version = system.GetLibraryVersion()
    print('Library version: %d.%d.%d.%d' % (version.major, version.minor, version.type, version.build))

    # Retrieve list of cameras from the system
    cam_list = system.GetCameras()

    num_cameras = cam_list.GetSize()

    print('Number of cameras detected: %d' % num_cameras)


## Ocean Optics의 USB 4000을 위한 환경 설정

사전설치 사항으로 SpectraSuite가 설치되어 WinUSB 드라이버가 작동하고 있어야 한다.

그렇지 않다면, libusb-win32를 설치하고 수작업으로 드라이버를 설정하고 설치해야 한다.

아직은 seabreeze가 libusb-1.0을 지원하고 있지는 않는 것 같아. 위의 방법이 유일한 것 같다.

그럼 python에서 usb4000을 운용할 seabreeze를 설치한다.

PS D:\> python -m pip install seabreeze

설치된 버전을 확인한다.

PS D:\> python

Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import seabreeze

>>> seabreeze.use('cseabreeze')

>>> from seabreeze.spectrometers import list_devices, Spectrometer

>>>  devices = list_devices()

  File "<stdin>", line 1

    devices = list_devices()

IndentationError: unexpected indent

>>> devices = list_devices()

>>> devices

[<SeaBreezeDevice USB4000:USB4U30285>]

설치는 잘 된 것 같다. 



2021년 1월 2일 토요일

VGG16 for 1D regression

 1. Build Model


2. Prepare the data using scaler

3. Do Training

4. Result