[AI] Python ๊ธฐ์ดˆ๋ฌธ๋ฒ• ๐Ÿ‘†๐Ÿป

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

DeepLearning

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

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

๊ฐ„๋‹จํ•˜๊ฒŒ ํ•ด๋ณธ Tensorflow, Yolo ๋“ฑ์„ ํ•ด๋ณธ ๊ฒฝํ—˜์œผ๋กœ
Deep Learning์„ ๋‹ค์‹œ ์‹œ์ž‘ํ–ˆ๋Š”๋ฐ
์ œ๋Œ€๋กœ ์•Œ๊ณ  ์žˆ๋Š” ๊ฒƒ์ด ์•„์˜ˆ ์—†์—ˆ๋‹ค. ๐Ÿ˜ข < (๋ˆ„๊ฐ€ ๋งŒ๋“ค์–ด๋†“์€๊ฑฐ ๊ฐ€์ ธ๋‹ค๋งŒ ์ผ๋‹ค.)

๋ฐ์ดํ„ฐ์…‹์„ ํ•™์Šต ์‹œ์ผœ ๊ฒฐ๊ณผ๋ฅผ ์–ป๊ณ ์‹ถ๋‹ค.

๊ธฐ๋ณธ ํ•™์Šต ์†Œ์Šค๋ฅผ ์ˆ˜์ •ํ•˜์—ฌ ๋†’์€ ์ •ํ™•๋„๋ฅผ ๊ฐ€์ง„ ๊ฒฐ๊ณผ๋ฅผ ์–ป๊ณ ์‹ถ๋‹ค.

์ •ํ™•ํ•œ ๊ฒฐ๊ณผ๋ฅผ ์–ป๊ธฐ ์œ„ํ•ด์„œ๋Š” ์†Œ์Šค ์ž‘์—…์„ ํ•ด์•ผํ•œ๋‹ค.

์†Œ์Šค๋ถ„์„ ๋ฐ ์ž‘์—…์ด ํ•„์š”ํ•œ๋ฐ, ๋Œ€๋ถ€๋ถ„ Python ์–ธ์–ด๋กœ ์ด๋ฃจ์–ด์ ธ์žˆ๊ณ 
์‚ฌ์šฉํ•˜๋ ค๋Š” Tensorflow๋ผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์กฐ์ฐจ Pythone์œผ๋กœ ๋˜์–ด์žˆ๋‹ค.
๊ทผ๋ฐ ๋‚˜๋Š” ๊ธฐ์ดˆ๊ฐ€ ์—†๋‹ค.๐Ÿ˜ฒ

๐Ÿ‘ ํŒŒ์ด์ฌ์ด ๋ฌด์—‡์ผ๊นŒ?

๋ชจ๋“  ํ˜„์—…์„ C#์œผ๋กœ ์ง„ํ–‰ํ•จ์— ๋”ฐ๋ผ, ๋‹ค๋ฅธ ์–ธ์–ด๋“ค์˜ ๊ธฐ์ดˆ๊ฐ€ ๋ถ€์กฑ.
๋ชจ๋“  ์–ธ์–ด์˜ ์ƒˆ๋กœ์šด ์‹œ์ž‘์€ ํ•ญ์ƒ ์‹ ์ด๋‚œ๋‹ค.๐Ÿ˜Š

  • ๋ฌด๋ฃŒ ์–ธ์–ด
  • ์‰ฌ์šด ์–ธ์–ด
  • ์ธ๊ฐ„์ ์ธ ๋ฌธ๋ฒ•์„ ๊ฐ€์ง„ ์–ธ์–ด
  • ๋น ๋ฅธ ๊ฐœ๋ฐœ ๊ฐ€๋Šฅ
  • ..........

์ข‹์€ ์–ธ์–ด๋„ค๐Ÿ‘

๐Ÿญ ํŒŒ์ด์ฌ ์ž๋ฃŒํ˜•

ํƒ€์ž…์˜ˆ์ œ
์ˆซ์žํ˜•(Number)์ •์ˆ˜:123, -345, 0, ์‹ค์ˆ˜:123.45, -1234.5, 3.4e10 8์ง„์ˆ˜: 0o34, 0o25, 16์ง„์ˆ˜: 0x2A, 0xFF
๋ฌธ์žํ˜•(String)โ€œHello Worldโ€, โ€˜Hello Worldโ€™ โ€œโ€โ€ Hello World! ํฌ์นด์นฉโ€ฆ โ€œโ€โ€
๋ฆฌ์ŠคํŠธ(List)[1, 2, 'one', 'two']
ํŠœํ”Œ(Tuple)(1, 2, 'one', 'two')
๋”•์…˜์–ด๋ฆฌ(Dictionary){ 1: โ€˜oneโ€™, 3: โ€˜threeโ€™}
์ด์ง„๊ฐ’(Boolean)์ฐธ : True, โ€˜โ€ฆโ€™, [โ€ฆ], 0 ์ด ์•„๋‹Œ ์ˆ˜ ๊ฑฐ์ง“ : False, โ€˜โ€™,โ€โ€, [], (), {}, 0, None

๐Ÿฎ ํŒŒ์ด์ฌ ๋ฌธ๋ฒ•(์ œ์–ด๋ช…๋ น, ํ•จ์ˆ˜, ํด๋ž˜์“ฐ, ์˜ˆ์™ธ์ฒ˜๋ฆฌ)

๊ณตํ†ต

  1. ( : ) ๋‹ค์Œ์„ ๊ธฐ์ค€์œผ๋กœ ๋“ค์—ฌ์“ฐ๊ธฐ ํ•„์ˆ˜(C# {}์™€ ๊ฐ™์€ ๊ธฐ๋Šฅ , ๋ธ”๋ก ์ฒ˜๋ฆฌ)
  2. ๋ณ€์ˆ˜๋ฅผ ๋”ฐ๋กœ ์„ ์–ธํ•  ํ•„์š”X -> ๋ฐ์ดํ„ฐ๋ฅผ ๋„ฃ์„ ๋•Œ ํ•ด๋‹น ๋ณ€์ˆ˜์˜ ํƒ€์ž… ํ• ๋‹น

๐ŸŒ› ์ œ์–ด๋ช…๋ น

IF

-์ฃผ๋จธ๋‹ˆ์— ๋ˆ์ด ์—†์œผ๋ฉด ํŽธ์˜์ ์„ ์ง€๋‚˜๊ฐ„๋‹ค.
-์ฃผ๋จธ๋‹ˆ์— ๋ˆ์ด ์žˆ์œผ๋ฉด์„œ 500์›์ด์ƒ ์žˆ์œผ๋ฉด ํฌ์นด์นฉ์„ ์‚ฌ๋จน๊ณ ,
-์ฃผ๋จธ๋‹ˆ์— ๋ˆ์ด ์žˆ์œผ๋ฉด์„œ 300์›์ด์ƒ 500์› ๋ฏธ๋งŒ์ผ ๊ฒฝ์šฐ ๊ปŒ์„ ์‚ฌ๋จน๊ณ ,
-์ฃผ๋จธ๋‹ˆ์— ๋ˆ์ด ์žˆ์œผ๋ฉด์„œ 300์›์ด ๋˜์ง€ ์•Š์„ ๊ฒฝ์šฐ์—๋Š” ํŽธ์˜์ ์„ ์ง€๋‚˜๊ฐ„๋‹ค.

C# IF๋ฌธ์ด๋ž‘ ๋‹ค๋ฅผ๊ฒŒ ์—†๋‹ค

pocket = ['money', 'handwash' , 'airpod']
money = 500
watch = 1
if 'money' in pocket :
  if money >= 500 :
    print ("ํฌ์นด์นฉ์„ ์‚ฌ๋จน์–ด~") 
  elif money >= 300 :
    print ("๊ปŒ์„ ์‚ฌ๋จน์–ด~") 
  else:
    print ("ํŽธ์˜์ ์„ ์ง€๋‚˜์ณ๋ผ~") 
elif watch : pass
else:
  print ("ํŽธ์˜์ ์„ ์ง€๋‚˜์ณ๋ผ~") 

๊ฒฐ๊ณผ
ํฌ์นด์นฉ์„ ์‚ฌ๋จน์–ด~

WHILE

  • 10๊ฐœ ์งœ๋ฆฌ์˜ ๊ณ„๋‹จ์„ ์˜ฌ๋ผ๊ฐ€๋ณด์ž.
  • break๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ฆ‰์‹œ ๋ฐ˜๋ณต๋ฌธ์—์„œ ๋น ์ ธ๋‚˜์˜จ๋‹ค.
coffee = 10
money = 300
while money:
  print("๋ˆ์„ ๋ฐ›์•˜์œผ๋‹ˆ ์ปคํ”ผ๋ฅผ ์ค๋‹ˆ๋‹ค.")
  coffee = coffee -1
  print("๋‚จ์€ ์ปคํ”ผ์˜ ์–‘์€ %d๊ฐœ์ž…๋‹ˆ๋‹ค." % coffee)
  if not coffee:
    print("์ปคํ”ผ๊ฐ€ ๋‹ค ๋–จ์–ด์กŒ์Šต๋‹ˆ๋‹ค. ํŒ๋งค๋ฅผ ์ค‘์ง€ํ•ฉ๋‹ˆ๋‹ค.")
    break

๊ฒฐ๊ณผ
๊ณ„๋‹จ์„ 1์นธ ์˜ฌ๋ผ๊ฐ”์Šต๋‹ˆ๋‹ค.
๊ณ„๋‹จ์„ 2์นธ ์˜ฌ๋ผ๊ฐ”์Šต๋‹ˆ๋‹ค.
...
๊ณ„๋‹จ์„ 10์นธ ์˜ฌ๋ผ๊ฐ”์Šต๋‹ˆ๋‹ค.
๊ณ„๋‹จ์„ ๋ชจ๋‘ ์˜ฌ๋ผ๊ฐ”์Šต๋‹ˆ๋‹ค.

FOR

  • 60์  ์ด์ƒ์ผ ๊ฒฝ์šฐ ํ•ฉ๊ฒฉ, ๋ฏธ๋งŒ์ผ ๊ฒฝ์šฐ ๋ถˆํ•ฉ๊ฒฉ์„ ์ถœ๋ ฅํ•˜์ž.
marks = [90, 25, 67, 45, 80]
number = 0
for mark in marks:
  number = number +1
  if mark >= 60:
    print("%d๋ฒˆ ํ•™์ƒ์€ ํ•ฉ๊ฒฉ์ž…๋‹ˆ๋‹ค." % number)
  else:
    print("%d๋ฒˆ ํ•™์ƒ์€ ๋ถˆํ•ฉ๊ฒฉ์ž…๋‹ˆ๋‹ค." % number)

๊ฒฐ๊ณผ
1๋ฒˆ ํ•™์ƒ์€ ํ•ฉ๊ฒฉ์ž…๋‹ˆ๋‹ค.
2๋ฒˆ ํ•™์ƒ์€ ๋ถˆํ•ฉ๊ฒฉ์ž…๋‹ˆ๋‹ค.
3๋ฒˆ ํ•™์ƒ์€ ํ•ฉ๊ฒฉ์ž…๋‹ˆ๋‹ค.
4๋ฒˆ ํ•™์ƒ์€ ๋ถˆํ•ฉ๊ฒฉ์ž…๋‹ˆ๋‹ค.
5๋ฒˆ ํ•™์ƒ์€ ํ•ฉ๊ฒฉ์ž…๋‹ˆ๋‹ค.


๐ŸŒž ํ•จ์ˆ˜

๊ธฐ๋Šฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋ธ”๋ก

๊ธฐ๋ณธ๊ตฌ์กฐ

def ํ•จ์ˆ˜๋ช…(์ž…๋ ฅ ์ธ์ˆ˜):
<์ˆ˜ํ–‰ํ•  ๋ฌธ์žฅ1>
<์ˆ˜ํ–‰ํ•  ๋ฌธ์žฅ2>
...

์˜ˆ์ œ

  • ์ด๋ฆ„, ์ด๋ฉ”์ผ, ์ „ํ™”๋ฒˆํ˜ธ, ๋ถ€๊ฐ€์„œ๋น„์Šค ํฌ๋ง ์œ ๋ฌด๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ์ถœ๋ ฅํ•ด๋ณด์ž.
def printUserInfo(name, email, telephone, isPremium):
  print("๋‚ด ์ด๋ฆ„์€ %s ์ด๋ฉฐ" % name)
  print("์ด๋ฉ”์ผ์€ %s " % email)
  print("๋ฒˆํ˜ธ๋Š” %s ์ž…๋‹ˆ๋‹ค." % telephone)
  if isPremium:
    print("๋ถ€๊ฐ€์„œ๋น„์Šค๋ฅผ ํฌ๋งํ•ฉ๋‹ˆ๋‹ค.")
  else:
    print("๋ถ€๊ฐ€์„œ๋น„์Šค๋ฅผ ํฌ๋งํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.")
printUserInfo("ํฌ์นด์นฉ", "ggg2323@email.com", "000-1234-5678", False)
printUserInfo("ํฌํ…Œํ† ์นฉ", "ggg3232@email.com", "000-9876-5432", True)

๊ฒฐ๊ณผ
๋‚ด ์ด๋ฆ„์€ ํฌ์นด์นฉ ์ด๋ฉฐ
์ด๋ฉ”์ผ์€ ggg2323@email.com
๋ฒˆํ˜ธ๋Š” 000-1234-5678 ์ž…๋‹ˆ๋‹ค.
๋ถ€๊ฐ€์„œ๋น„์Šค๋ฅผ ํฌ๋งํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
๋‚ด ์ด๋ฆ„์€ ํฌํ…Œํ† ์นฉ ์ด๋ฉฐ
์ด๋ฉ”์ผ์€ ggg3232@email.com
๋ฒˆํ˜ธ๋Š” 000-9876-5432 ์ž…๋‹ˆ๋‹ค.
๋ถ€๊ฐ€์„œ๋น„์Šค๋ฅผ ํฌ๋งํ•ฉ๋‹ˆ๋‹ค.

๊ธฐํƒ€
input() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์‚ฌ์šฉ์ž๊ฐ€ ์ง์ ‘ ๋ฐ์ดํ„ฐ๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ๋‹ค.

number = input("์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”: ")
print(number)

๐ŸŒŸ ํด๋ž˜์Šค(class)

ํด๋ž˜์Šค(class)๋Š” ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฌผ(instance)๋ฅผ ๋งŒ๋“œ๋Š”๋ฐ ํ‹€, ๊ณต์žฅ๊ณผ ๊ฐ™์€ ์—ญํ• 
ํŒŒ์ด์ฌ์˜ ํ•ต์‹ฌ ๊ธฐ๋Šฅ

๊ธฐ๋ณธ๊ตฌ์กฐ

class ํด๋ž˜์Šค์ด๋ฆ„[(์ƒ์† ํด๋ž˜์Šค๋ช…)]:
<ํด๋ž˜์Šค ๋ณ€์ˆ˜ 1>
<ํด๋ž˜์Šค ๋ณ€์ˆ˜ 2>
...
def ํด๋ž˜์Šคํ•จ์ˆ˜1(self[, ์ธ์ˆ˜1, ์ธ์ˆ˜2,,,]):
<์ˆ˜ํ–‰ํ•  ๋ฌธ์žฅ 1>
<์ˆ˜ํ–‰ํ•  ๋ฌธ์žฅ 2>
...
def ํด๋ž˜์Šคํ•จ์ˆ˜2(self[, ์ธ์ˆ˜1, ์ธ์ˆ˜2,,,]):
<์ˆ˜ํ–‰ํ•  ๋ฌธ์žฅ1>
<์ˆ˜ํ–‰ํ•  ๋ฌธ์žฅ

์˜ˆ์ œ

  • Cafe๋ผ๋Š” Class๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž.
  • Cafe Class๋ฅผ ์ƒ์†๋ฐ›์•„ ํŒŒ์Šค์ฟ ์ฐŒ Class๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž.
  • ๊ฐ์ฒด(Object)๋Š” ์†Œํ”„ํŠธ์›จ์–ด ์„ธ๊ณ„์— ๊ตฌํ˜„ํ•  ๋Œ€์ƒ์ด๊ณ , ์ด๋ฅผ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•œ ์„ค๊ณ„๋„๊ฐ€ ํด๋ž˜์Šค(Class)์ด๋ฉฐ, ์ด ์„ค๊ณ„๋„์— ๋”ฐ๋ผ ์†Œํ”„ํŠธ์›จ์–ด ์„ธ๊ณ„์— ๊ตฌํ˜„๋œ ์‹ค์ฒด๊ฐ€ ์ธ์Šคํ„ด์Šค(Instance)์ด๋‹ค.

๊ธฐ๋ณธ

class Cafe:
  manager = ""
  def __init__(self, name):
    self.manager = name
  def PrintCafeInfo(self, where):
    print(" ์นดํŽ˜ ๋งค๋‹ˆ์ € ์ด๋ฆ„์€ %s์ด๋ฉฐ." % self.manager)
    print(" ์นดํŽ˜์˜ ์œ„์น˜๋Š” %s์ด๋‹ค." % where)
cafe = Cafe("ํฌ์นด์นฉ") #cafe๋Š” ๊ฐ์ฒด
cafe.PrintCafeInfo("์ˆ˜์›")

๊ฒฐ๊ณผ
์นดํŽ˜ ๋งค๋‹ˆ์ € ์ด๋ฆ„์€ ํฌ์นด์นฉ์ด๋ฉฐ.
์นดํŽ˜์˜ ์œ„์น˜๋Š” ์ˆ˜์›์ด๋‹ค.

์ƒ์†

class PascucciCafe(Cafe):
  def PrintCafeInfo(self, where):
    print(" ์นดํŽ˜ ๋งค๋‹ˆ์ € ์ด๋ฆ„์€ %s์ด๋ฉฐ." % self.manager)
    print(" ์นดํŽ˜์˜ ์œ„์น˜๋Š” %s ์ด๋‹ค." % where)
    print(" ์นดํŽ˜์˜ ๋ธŒ๋žœ๋“œ ๋ช…์€ ํŒŒ์Šค์ฟ ์ฐŒ๋‹ค.")
pascucciCafe = PascucciCafe("ํฌํ…Œํ† ์นฉ")
pascucciCafe.PrintCafeInfo("์šฉ์ธ")

๊ฒฐ๊ณผ
์นดํŽ˜ ๋งค๋‹ˆ์ € ์ด๋ฆ„์€ ํฌํ…Œํ† ์นฉ์ด๋ฉฐ.
์นดํŽ˜์˜ ์œ„์น˜๋Š” ์šฉ์ธ ์ด๋‹ค.
์นดํŽ˜์˜ ๋ธŒ๋žœ๋“œ ๋ช…์€ ํŒŒ์Šค์ฟ ์ฐŒ๋‹ค.


๐ŸŒ ์˜ˆ์™ธ์ฒ˜๋ฆฌ

ํด๋ž˜์Šค(class)๋Š” ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฌผ(instance)๋ฅผ ๋งŒ๋“œ๋Š”๋ฐ ํ‹€, ๊ณต์žฅ๊ณผ ๊ฐ™์€ ์—ญํ• 
ํŒŒ์ด์ฌ์˜ ํ•ต์‹ฌ ๊ธฐ๋Šฅ

๊ธฐ๋ณธ๊ตฌ์กฐ

try :
์ž‘์—… ํ•  ๊ฒƒ
except ValueError : ์—๋Ÿฌ ์ข…๋ฅ˜
์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๋Š” ์ฝ”๋“œ
์—๋Ÿฌ๊ฐ€ ๋‚˜์™”์„ ๋•Œ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ฃผ์ž.
finally :
ํ•ญ์ƒ ์‹คํ–‰ํ•˜๋Š” ๊ณณ
๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ ์‹œ ์ด ๋ถ€๋ถ„์—์„œ ๋ฉ”๋ชจ๋ฆฌ ์ •๋ฆฌ๋ฅผ ํ•ด์ฃผ๋„๋ก ํ•˜์ž

์˜ˆ์ œ

  • ๋ฌธ์žํ˜•์„ intํ˜•์œผ๋กœ ๋ฐ”๊ฟ” ์˜ค๋ฅ˜๋ฅผ ๋งŒ๋“ค์ž.
  • ์˜ค๋ฅ˜ ์ƒ๊ฒผ์„ ๋•Œ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด๋ณด์ž.
text = '100%'
try :
  number = int(text) 
except ValueError :  
  print('{}๋Š” ์ˆซ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.'.format(text)) 
finally :
  print("์ž‘์—…๋") 

๊ฒฐ๊ณผ
100%๋Š” ์ˆซ์ž๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.
์ž‘์—…๋

๐ŸŒน ๊ฒฐ๋ก 

C# ๋ฌธ๋ฒ•๊ณผ ๊ฐœ๋…์ด ๋น„์Šท.
์‚ฌ์šฉ๋ฒ•์ด ์‰ฝ๊ณ  ๊ฐ„๋‹จ.
ํŒŒ์ด์ฌ ๊ธฐ๋ณธ ๋ฌธ๋ฒ•์„ ์ตํ˜”์œผ๋‹ˆ, Tensorflow ํ•™์Šต์„ ์‹œ์ž‘ํ•ด๋ณด์ž.

์ถœ์ฒ˜ ๋ฐ ์ฐธ์กฐ : Doit_์ ํ”„ํˆฌํŒŒ์ด์ฌ
profile
์•ˆ๋…•ํ•˜์„ธ์š”. ๋ฐ์ดํ„ฐ์™€ ๋™๊ณ ๋™๋ฝ ์ค‘์ธ ๊ฐœ๋ฐœ์ž ์ž…๋‹ˆ๋‹ค.
post-custom-banner

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