Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tensorflow
GitHub Repository: tensorflow/docs-l10n
Path: blob/master/site/ko/js/tutorials/setup.md
25118 views

설정

브라우저 설정

브라우저 기반 프로젝트에서 TensorFlow.js를 가져오는 두 가지 주요 방법이 있습니다.

웹 개발이 처음이거나 webpack 또는 parcel과 같은 도구에 대해 들어 본 적이 없는 경우 스크립트 태그 접근 방식을 사용하는 것이 좋습니다. 이미 웹 개발 경험이 있거나 더 큰 규모의 프로그램을 작성하려는 경우 빌드 도구를 사용하여 탐색하는 것이 좋습니다.

스크립트 태그를 통한 사용법

기본 HTML 파일에 다음 스크립트 태그를 추가합니다.

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>

스크립트 태그 설정 코드 샘플 보기

// 선형 회귀 모델을 정의합니다. const 모델 = tf.sequential (); model.add (tf.layers.dense ({units : 1, inputShape : [1]}));

model.compile ({loss : 'meanSquaredError', 최적화 프로그램 : 'sgd'});

// 훈련을 위해 합성 데이터를 생성합니다. const xs = tf.tensor2d ([1, 2, 3, 4], [4, 1]); const ys = tf.tensor2d ([1, 3, 5, 7], [4, 1]);

// Train the model using the data. model.fit(xs, ys, {epochs: 10}).then(() =&amp;gt; { // Use the model to do inference on a data point the model hasn't seen before: model.predict(tf.tensor2d([5], [1, 1])).print(); // Open the browser devtools to see the output });

NPM에서 설치

npm cli 도구 또는 yarn을 사용하여 TensorFlow.js를 설치할 수 있습니다.

yarn add @tensorflow/tfjs

또는

npm install @tensorflow/tfjs

NPM을 통한 설치 샘플 코드 보기

import * as tf from '@tensorflow/tfjs';

// Define a model for linear regression. const model = tf.sequential (); model.add(tf.layers.dense({units: 1, inputShape: [1]}));

model.compile ({loss : 'meanSquaredError', 최적화 프로그램 : 'sgd'});

// 훈련을 위해 합성 데이터를 생성합니다. const xs = tf.tensor2d ([1, 2, 3, 4], [4, 1]); const ys = tf.tensor2d ([1, 3, 5, 7], [4, 1]);

// Train the model using the data. model.fit(xs, ys, {epochs: 10}).then(() =&amp;gt; { // Use the model to do inference on a data point the model hasn't seen before: model.predict(tf.tensor2d([5], [1, 1])).print(); // Open the browser devtools to see the output });

Node.js 설정

npm cli 도구 또는 yarn 을 사용하여 TensorFlow.js를 설치할 수 있습니다.

옵션 1: 네이티브 C++ 바인딩으로 TensorFlow.js를 설치합니다.

yarn add @tensorflow/tfjs-node

또는

npm install @tensorflow/tfjs-node

옵션 2: (Linux 전용) 시스템에 CUDA를 지원하는 NVIDIA® GPU가 있는 경우 GPU 패키지를 사용하여 성능을 끌어올릴 수 있습니다.

yarn add @tensorflow/tfjs-node-gpu

또는

npm install @tensorflow/tfjs-node-gpu

옵션 3: pure JavaScript 버전을 설치합니다. 이 버전은 성능면에서 가장 느린 옵션입니다.

yarn add @tensorflow/tfjs

또는

npm install @tensorflow/tfjs

Node.js 사용법에 대한 샘플 코드 보기

const tf = require('@tensorflow/tfjs');

// 선택 사항 바인딩로드 : // GPU로 실행하는 경우 '@ tensorflow / tfjs-node-gpu'를 사용합니다. require ( '@ tensorflow / tfjs-node');

// 간단한 모델 학습 : const model = tf.sequential (); model.add (tf.layers.dense ({units : 100, 활성화 : 'relu', inputShape : [10]})); model.add (tf.layers.dense ({units : 1, activation : 'linear'})); model.compile ({optimizer : 'sgd', 손실 : 'meanSquaredError'});

const xs = tf.randomNormal ([100, 10]); const ys = tf.randomNormal ([100, 1]);

model.fit (xs, ys, {epochs : 100, callbacks : {onEpochEnd : (epoch, log) => console.log ( Epoch ${epoch}: loss = ${log.loss} )}});

TypeScript

TypeScript를 사용할 때 프로젝트에서 엄격한 null 검사를 사용하거나 컴파일 중에 오류가 발생하는 경우 tsconfig.json 파일에서 skipLibCheck: true를 설정해야 할 수 있습니다.