[AI] Tensorflow ๊ธฐ๋ณธ๊ฐœ๋… ๐Ÿ‘†๐Ÿป

๊ฐœ๋ฐœVelogยท2020๋…„ 7์›” 27์ผ
1

DeepLearning

๋ชฉ๋ก ๋ณด๊ธฐ
5/10
post-custom-banner

๐Ÿค– ์ธ๊ณต์ง€๋Šฅ์„ ๋‹ค์‹œ ์‹œ์ž‘ํ•ด๋ณด์ž 2

Python๋ผ๋Š” ๊ฒƒ์„ ๊ฐ„๋‹จํ•˜๊ฒŒ ์‚ดํŽด๋ณด์•˜๊ณ  (ํ•ด๋‹น๋งํฌ)
ํ•ด๋‹น ์–ธ์–ด๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋Š” Tensorflow๋ฅผ ํ•™์Šตํ•ด๋ณด๋ ค๊ณ  ํ•œ๋‹ค.

Tensorflow์˜ ๊ฐœ๋…์„ ๊ณต๋ถ€ํ•ด๋ณด์ž

Tensorflow ์˜ˆ์ œ๋ฅผ ๋Œ๋ ค๋ณด์ž

๋‚ด๊ฐ€ ์›ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋กœ ํ•™์Šต์„ ์‹œํ‚ค๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋„์ถœํ•ด๋ณด์ž


๐ŸŒŠ Tensorflow ๋ฌด์—‡์ผ๊นŒ?

๋”ฑ๋”ฑํ•œ ์ •์˜

  • ํ…์„œํ”Œ๋กœ์šฐ(TensorFlow)๋Š” ๊ธฐ๊ณ„ ํ•™์Šต๊ณผ ๋”ฅ๋Ÿฌ๋‹์„ ์œ„ํ•ด ๊ตฌ๊ธ€์—์„œ ๋งŒ๋“  ์˜คํ”ˆ์†Œ์Šค ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
  • ๋ฐ์ดํ„ฐ ํ”Œ๋กœ์šฐ ๊ทธ๋ž˜ํ”„(Data Flow Graph) ๋ฐฉ์‹์„ ์‚ฌ์šฉ

๋‚ด๊ฐ€ ๋”ฅ๋Ÿฌ๋‹์„ ํ•ด๋ณด๊ธฐ์œ„ํ•ด ํ•„์ˆ˜๋กœ ์•Œ์•„์•ผ๋˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

๋ฐ์ดํ„ฐ ํ”Œ๋กœ์šฐ ๊ทธ๋ž˜ํ”„(Data Flow Graph)๋ž€?
Data Flow Graph

  • ๋ฐ์ดํ„ฐ ํ”Œ๋กœ์šฐ ๊ทธ๋ž˜ํ”„๋Š” ์ˆ˜ํ•™ ๊ณ„์‚ฐ๊ณผ ๋ฐ์ดํ„ฐ์˜ ํ๋ฆ„์„ ๋…ธ๋“œ(Node)์™€ ์—ฃ์ง€(Edge)๋ฅผ ์‚ฌ์šฉํ•œ
    ๋ฐฉํ–ฅ ๊ทธ๋ž˜ํ”„(Directed Graph)๋กœ ํ‘œํ˜„
  • ๋…ธ๋“œ๋Š” ์ˆ˜ํ•™์  ๊ณ„์‚ฐ, ๋ฐ์ดํ„ฐ ์ž…/์ถœ๋ ฅ, ๊ทธ๋ฆฌ๊ณ  ๋ฐ์ดํ„ฐ์˜ ์ฝ๊ธฐ/์ €์žฅ ๋“ฑ์˜ ์ž‘์—…์„ ์ˆ˜ํ–‰
  • ์—ฃ์ง€๋Š” ๋…ธ๋“œ๋“ค ๊ฐ„ ๋ฐ์ดํ„ฐ์˜ ์ž…์ถœ๋ ฅ ๊ด€๊ณ„๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.
  • ์—ฃ์ง€๋Š” Tensor(๋‹ค์ฐจ์› ๋ฐ์ดํ„ฐ ๋ฐฐ์—ด)๋ฅผ ์‹ค์–ด ๋‚˜๋ฅด๋Š”๋ฐ, ์ด๊ฒƒ์ด ๊ณง Tensorflow

Tensorflow๋ฅผ ์ •ํ™•ํ•˜๊ฒŒ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” Tensor๊ฐ€ ๋ฌด์—‡์ธ์ง€ ์•Œ์•„์•ผํ• ๋“ฏ?!!


๐Ÿ“ฆ Tensor ๋ฌด์—‡์ผ๊นŒ?

  • ์ธ๊ณต์ง€๋Šฅ์—์„œ์˜ ํ…์„œ(Tensor)๋Š” ์ˆ˜ํ•™์  ๊ฐœ๋…์˜ ๋‹ค์ฐจ์› ๋ฐฐ์—ด

    ํ…์„œ(Tensor)๋ฅผ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด Rank, shape, type๋ฅผ ์•Œ์•„์•ผ ํ•œ๋‹ค.

โš™๏ธ Rank

  • ํ…์„œ(Tensor)์˜ ์ฐจ์›์„ ์˜๋ฏธ
RANKTYPEEXAMPLE
0Scalar[1]
1Vector[1,1]
2Matrix[[1,1],[1,1]]
33 Tensor[[[1,1],[1,1]],[[1,1],[1,1]]]
4N Tensor[[[[1,1],[1,1]],[[1,1],[1,1]]]................



์ด๋ฏธ์ง€ ์ฐธ์กฐ : https://hiddenbeginner.github.io/deeplearning/2020/01/21/pytorch_tensor.html

  • 0์ฐจ ํ…์„œ : ๋ฒกํ„ฐ๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์— ์Šค์นผ๋ผ
  • 1์ฐจ ํ…์„œ : ๋ฒกํ„ฐ๊ฐ€ ํ•˜๋‚˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฒกํ„ฐ
  • 2์ฐจ ํ…์„œ : ๋ฒกํ„ฐ๊ฐ€ ๋‘ ๊ฐœ ์ผ๋ ฌ๋กœ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํ–‰๋ ฌ์ด๋‚˜ ๋‹ค์ด์• ๋“œ
  • 3์ฐจ ํ…์„œ : 2์ฐจ ํ…์„œ๊ฐ€ ๊ฐ€ ์ผ๋ ฌ๋กœ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํŠธ๋ผ์ด์• ๋“œ
  • N์ฐจ ํ…์„œ : n-1 ์ฐจ ํ…์„œ๊ฐ€ ์ผ๋ ฌ๋กœ ๊ตฌ์„ฑ

์ฐจ์›์˜ ์ˆ˜

โš™๏ธ shape

RANKSHAPEDIMENSION NUMBEREXAMPLE
0[]0-DA 0-D tensor, A scalar
1[DO]1-DA 1-D tensor with shape[5]
2[DO,D1]2-DA 2-D tensor with shape[3,4]
3[DO,D1,D2]3-D2-D
4[DO,D1,...Dn-1]n-DA tensor with shape[DO,D1,...Dn-1]
  • ๊ฐ ์ถ•์ด ๋ช‡ ๊ฐœ์˜ ์—˜๋ฆฌ๋จผํŠธ(Element)๋กœ ๊ตฌ์„ฑ๋˜์–ด์žˆ๋Š”์ง€ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฐ’
  • ์ฐจ์›๊ณผ ํ•จ๊ป˜ ๋ช‡๊ฐœ์˜ ์›์†Œ๋“ค๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋Š”์ง€์˜ ์—ฌ๋ถ€ ํŒŒ์•… ๊ฐ€๋Šฅ.

โš™๏ธ Type

Data TypePython TypeDescripiton
DT_FLOATtf.float3232 bits floating point
DT_DOUBLEtf.float6464 bits floating point
DT_INT8tf.int88 bits signed integer
DT_INT16tf.int1616 bits signed integer
DT_INT32tf.int3232 bits signed integer
DT_INT64tf.int6464 bits signed integer
์ถœ์ฒ˜ ๋ฐ ์ฐธ์กฐ : https://www.tensorflow.org/tutorials
profile
์•ˆ๋…•ํ•˜์„ธ์š”. ๋ฐ์ดํ„ฐ์™€ ๋™๊ณ ๋™๋ฝ ์ค‘์ธ ๊ฐœ๋ฐœ์ž ์ž…๋‹ˆ๋‹ค.
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€