Tensorflow - 텐서플로우

김성진·2021년 1월 12일
0
post-thumbnail

Tensorflow란..

Tensorflow는 다양한 작업에 대해 데이터 흐름 프로그래밍을 위한 오픈소스 소프트웨어 라이브러리이다. 머신러닝과 연관있는 라이브러리이다. Pytorch는 학계에서 연구용으로 사용된다면 텐서플로는 산업계에서 실전으로 더 많이 사용된다고 한다. (2020년 기준)

Tensorflow 사용

자바스크립트로도 제공이 되지만 가장 많이 사용되는 것은 python 형태입니다. 그리고 Jupyter notebook을 설치해야 실행할 수 있다.
jupyter notebook

혹은 모든 기능이 이미 설치되어 있는 "구름IDE" (www.groom.io)라는 브라우저를 통해 사용할 수 있다. 회원가입 로그인 하는 것으로 무료 이용 가능.

텐서플로우 실전연습:

1.데이터 생성 자바스크립트 코드

// 인자로 주어진 설정에 따른 임의의 데이터 생성
const createData = ({xMin, xMax, weight, bias, count}) => {
  const xArray = []
  const yArray = []
​
  for (let i = 0; i < count; i++) {
    let yValue = 0
    const xValue = Math.round((xMin + Math.random() * (xMax - xMin)) * 10) / 10
    xArray.push(xValue)
    yValue += xValue * (weight * randomOffset(0.05));
​
    yValue += bias * randomOffset(0.005)
    yValue = Math.round(yValue * 10) / 10
    yArray.push(yValue)
  }
​
  return {
    xAry: xArray,
    yAry: yArray
  }
}
​
// 주어진 범위 이내의 오차값 적용
const randomOffset = (max) => {
  const offset = max * Math.random() * (Math.random() > 0.5 ? 1 : -1)
  return 1 + offset
}
​
const resultData = createData({
  xMin: 0,      // x 최소값
  xMax: 25,     // x 최대값
  weight: 3.2,  // 기울기
  bias: 256,    // x = 0시 y좌표
  count: 100    // 생성할 점 갯수
})
​
// 주피터 노트북에 붙여넣을 것
console.log(`x = [${resultData.xAry}]\ny = [${resultData.yAry}]`)
​
// 플라스크 웹앱에 붙여넣을 것
console.log(resultData.xAry.toString())
console.log(resultData.yAry.toString())

위 코드를 chrome에서 console창에 복붙하고 엔터를 치면 결과가 나온다. 그 결과를 jupyter notebook에 그대로 가져다 놓으면 아래와 같은 그래프를 볼 수 있다.

텐서플로우를 사용해 실제 산업에 적용한 예를 들자면;
한 배달음식점에서 돌리는 전단지 부수판매량의 관계 등을 파악하는데 실제로 유용하게 사용될 수 있다. (아래 그래프 참조)

profile
multi-national communicator with programming (back-end)

0개의 댓글