{"id":7805,"date":"2019-08-16T12:11:53","date_gmt":"2019-08-16T03:11:53","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=7805"},"modified":"2020-05-28T10:18:15","modified_gmt":"2020-05-28T01:18:15","slug":"model-%ed%99%95%ec%9e%a5%ea%b3%bc-%ea%b0%80%ec%a4%91%ec%b9%98%ea%b0%92-%ec%b5%9c%ec%a0%81%ed%99%94-%eb%b0%a9%eb%b2%95-%eb%b3%80%ea%b2%bd%ec%9d%84-%ed%86%b5%ed%95%9c-%ec%a0%95%ed%99%95%eb%8f%84","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=7805","title":{"rendered":"Model \ud655\uc7a5\uacfc \uac00\uc911\uce58\uac12 \ubcc0\uacbd\uc744 \ud1b5\ud55c \uc608\uce21 \uc815\ud655\ub3c4 \ud5a5\uc0c1"},"content":{"rendered":"<p>\uc774\uc804\uc5d0 \uc791\uc131\ud55c &#8220;PyTorch\ub97c \uc774\uc6a9\ud55c \uac04\ub2e8\ud55c \uba38\uc2e0\ub7ec\ub2dd&#8221;\uc774\ub77c\ub294 \uc544\ub798\uc758 \uae00\uc5d0\uc11c\ub294 \uc740\ub2c9\uce35\uc774 \uc5c6\ub294 \uc785\ub825\uacfc \ucd9c\ub825\uce35\uc73c\ub85c\ub9cc \uad6c\uc131\ub41c \ubaa8\ub378\uc744 \uc0ac\uc6a9\ud588\uc2b5\ub2c8\ub2e4. \uadf8\ub9ac\uace0 \uac00\uc911\uce58 \ubc0f \ud3b8\ud5a5\uac12\uc758 \ucd5c\uc801\ud654\ub97c \uc704\ud55c \ubc29\ubc95\uc740 SGD, \uc989 \ud655\ub960\uc801 \uacbd\uc0ac\ud558\uac15\uc744 \uc0ac\uc6a9\ud588\uc2b5\ub2c8\ub2e4. \uc815\ud655\ub3c4\ub294 \ub300\ub7b5 90%\uc815\ub3c4 \ub098\uc654\uc5c8\uc2b5\ub2c8\ub2e4.<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"p9u6fMkdNf\"><p><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=7755\">PyTorch\ub97c \uc774\uc6a9\ud55c \uac04\ub2e8\ud55c \uba38\uc2e0\ub7ec\ub2dd<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;PyTorch\ub97c \uc774\uc6a9\ud55c \uac04\ub2e8\ud55c \uba38\uc2e0\ub7ec\ub2dd&#8221; &#8212; GIS Developer\" src=\"http:\/\/www.gisdeveloper.co.kr\/?p=7755&#038;embed=true#?secret=lBKxHjOnQo#?secret=p9u6fMkdNf\" data-secret=\"p9u6fMkdNf\" width=\"525\" height=\"296\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>\uc774\uc5d0 \ub300\ud574 \uc740\ub2c9\uce35\uc744 2\uac1c \ucd94\uac00\ud558\uace0 \ub9e4\uac1c\ubcc0\uc218\uc758 \ucd5c\uc801\ud654\ub97c \uc704\ud55c \ubc29\uc2dd\uc744 SGD\uac00 \uc544\ub2cc Adam\uc744 \uc0ac\uc6a9\ud558\uc5ec \uc815\ud655\ub3c4\ub97c \ud5a5\uc0c1\uc2dc\ucf1c \ubcf4\uaca0\uc2b5\ub2c8\ub2e4. \uc740\ub2c9\uce35\uc774 \ucd94\uac00 \ub418\uc5c8\uc73c\ubbc0\ub85c \ud65c\uc131\ud654 \ud568\uc218\uac00 \ud544\uc694\ud55c\ub370, \uc5ed\uc804\ud30c\uc5d0\uc11c \ubbf8\ubd84\uac12 \uc18c\uc2e4(Vanishing Gradient)\uc774 \ubc1c\uc0dd\ud560 \uac00\ub2a5\uc131\uc774 \ud070 \uc2dc\uadf8\ubaa8\uc774\ub4dc \ud568\uc218\uac00 \uc544\ub2cc ReLU \ud568\uc218\ub97c \uc0ac\uc6a9\ud569\ub2c8\ub2e4. \uc989, \ubaa8\ub378\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/08\/model_784_255_255_10.png\" alt=\"\" width=\"75%\" class=\"aligncenter size-full wp-image-7807\" \/><\/p>\n<p>\uc704 \ubaa8\ub378\uc744 \uad6c\uc131\ud558\uae30 \uc704\ud55c PyTorch\uc758 \ucf54\ub4dc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nlinear1 = torch.nn.Linear(784, 256, bias=True).to(device)\r\nlinear2 = torch.nn.Linear(256, 256, bias=True).to(device)\r\nlinear3 = torch.nn.Linear(256, 10, bias=True).to(device)\r\nrelu = torch.nn.ReLU()\r\nmodel = torch.nn.Sequential(linear1, relu, linear2, relu, linear3).to(device)\r\n<\/pre>\n<p>\uadf8\ub9ac\uace0 \ub9e4\uac1c\ubcc0\uc218\uc5d0 \ub300\ud55c \ucd5c\uc801\ud654 \ubc29\ubc95\uc744 Adam\uc744 \uc0ac\uc6a9\ud558\ubbc0\ub85c \uc774\uc5d0 \ub300\ud55c \ucf54\ub4dc\ub294 \uc544\ub798\uc640 \uac19\uad6c\uc694. \uac01 \ucd5c\uc801\ud654 \ubc29\uc2dd\uc774 \uc5b4\ub5a4\uc2dd\uc73c\ub85c \uc791\ub3d9\ud558\ub294\uc9c0 \uc2dc\uac01\uc801\uc73c\ub85c \ud655\uc778\ud560 \uc218 \uc788\ub294 \uc720\uc6a9\ud55c \uc0ac\uc774\ud2b8\uc778 http:\/\/www.denizyuret.com\/2015\/03\/alec-radfords-animations-for.html\uc744 \ucc38\uace0\ud558\uc2dc\uae30 \ubc14\ub78d\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\noptimizer = torch.optim.Adam(model.parameters(), lr=0.001)\r\n<\/pre>\n<p>\uae30\uc874\uc758 \uc18c\uc2a4\ucf54\ub4dc\uc5d0\uc11c \uc704\uc758 \ubcc0\uacbd\ub41c \ubd80\ubd84\uc774 \ubc18\uc601\ub41c \uc804\uccb4 \ucf54\ub4dc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport torch\r\nimport torchvision\r\n\r\nbatch_size = 1000\r\n\r\nmnist_train = torchvision.datasets.MNIST(root=\"MNIST_data\/\", train=True, transform=torchvision.transforms.ToTensor(), download=True)\r\nmnist_test = torchvision.datasets.MNIST(root=\"MNIST_data\/\", train=False, transform=torchvision.transforms.ToTensor(), download=True)\r\ndata_loader = torch.utils.data.DataLoader(mnist_train, batch_size=batch_size, shuffle=True, drop_last=True)\r\n\r\ndevice = torch.device(\"cuda:0\")\r\n\r\nlinear1 = torch.nn.Linear(784, 256, bias=True).to(device)\r\nlinear2 = torch.nn.Linear(256, 256, bias=True).to(device)\r\nlinear3 = torch.nn.Linear(256, 10, bias=True).to(device)\r\nrelu = torch.nn.ReLU()\r\nmodel = torch.nn.Sequential(linear1, relu, linear2, relu, linear3).to(device)\r\n\r\nloss = torch.nn.CrossEntropyLoss().to(device)\r\noptimizer = torch.optim.Adam(model.parameters(), lr=0.001)\r\n\r\ntotal_batch = len(data_loader)\r\ntraining_epochs = 15\r\n\r\nfor epoch in range(training_epochs):\r\n    total_cost = 0\r\n\r\n    for X, Y in data_loader:\r\n        X = X.view(-1, 28 * 28).to(device)\r\n        Y = Y.to(device)\r\n        \r\n        hypothesis = model(X)\r\n        cost = loss(hypothesis, Y)\r\n\r\n        optimizer.zero_grad()\r\n        cost.backward()\r\n        optimizer.step()\r\n\r\n        total_cost += cost \r\n\r\n    avg_cost = total_cost \/ total_batch\r\n    print(\"Epoch:\", \"%03d\" % (epoch+1), \"cost =\", \"{:.9f}\".format(avg_cost))\r\n\r\nwith torch.no_grad():\r\n    X_test = mnist_test.data.view(-1, 28 * 28).float().to(device)\r\n    Y_test = mnist_test.targets.to(device)\r\n    prediction = model(X_test)\r\n    correct_prediction = torch.argmax(prediction, 1) == Y_test\r\n    accuracy = correct_prediction.float().mean()\r\n    print(\"Accuracy: \", accuracy.item())\r\n<\/pre>\n<p>\ucd5c\uc801\ud654 \uae30\ubc95\ub9c8\ub2e4 \ud559\uc2b5\ub960\uc758 \uac12\uc740 \ub2e4\ub985\ub2c8\ub2e4. \ubb3c\ub860 \uc5d0\ud3ed\uc5d0 \ub300\ud55c \ubc18\ubcf5\uc218\ub3c4 \ub2ec\ub77c\uc9c8 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ub7ec\ud55c \ubaa8\ub378\uc758 \uad6c\uc131\uacfc \ud558\uc774\ud37c \ud30c\ub77c\uba54\ud130\uc778 \ud559\uc2b5\ub960\uacfc \ubc18\ubcf5 \uc5d0\ud3ed\uc218 \ub4f1\uc740 AI \uc804\ubb38\uac00\uac00 \uc0c1\ud669\uc5d0 \ub530\ub77c \uacb0\uc815\ud574\uc57c \ud569\ub2c8\ub2e4. \uacb0\uacfc\uc801\uc73c\ub85c \uc704\uc640 \uac19\uc740 \ubaa8\ub378\uc758 \ud655\uc7a5\uacfc \ucd5c\uc801\ud654 \ubc29\ubc95\uc758 \ubcc0\uacbd \ub4f1\uc744 \ud1b5\ud55c \uc815\ud655\ub3c4\ub294 \uc57d 97%\ub85c \ucd9c\ub825\ub418\ub294\ub370, \uae30\uc874\uc758 90%\uc5d0\uc11c \ub300\ud3ed \ud5a5\uc0c1\ub41c \uac83\uc744 \uc54c \uc218 \uc788\uc2b5\ub2c8\ub2e4. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uc774\uc804\uc5d0 \uc791\uc131\ud55c &#8220;PyTorch\ub97c \uc774\uc6a9\ud55c \uac04\ub2e8\ud55c \uba38\uc2e0\ub7ec\ub2dd&#8221;\uc774\ub77c\ub294 \uc544\ub798\uc758 \uae00\uc5d0\uc11c\ub294 \uc740\ub2c9\uce35\uc774 \uc5c6\ub294 \uc785\ub825\uacfc \ucd9c\ub825\uce35\uc73c\ub85c\ub9cc \uad6c\uc131\ub41c \ubaa8\ub378\uc744 \uc0ac\uc6a9\ud588\uc2b5\ub2c8\ub2e4. \uadf8\ub9ac\uace0 \uac00\uc911\uce58 \ubc0f \ud3b8\ud5a5\uac12\uc758 \ucd5c\uc801\ud654\ub97c \uc704\ud55c \ubc29\ubc95\uc740 SGD, \uc989 \ud655\ub960\uc801 \uacbd\uc0ac\ud558\uac15\uc744 \uc0ac\uc6a9\ud588\uc2b5\ub2c8\ub2e4. \uc815\ud655\ub3c4\ub294 \ub300\ub7b5 90%\uc815\ub3c4 \ub098\uc654\uc5c8\uc2b5\ub2c8\ub2e4. PyTorch\ub97c \uc774\uc6a9\ud55c \uac04\ub2e8\ud55c \uba38\uc2e0\ub7ec\ub2dd \uc774\uc5d0 \ub300\ud574 \uc740\ub2c9\uce35\uc744 2\uac1c \ucd94\uac00\ud558\uace0 \ub9e4\uac1c\ubcc0\uc218\uc758 \ucd5c\uc801\ud654\ub97c \uc704\ud55c \ubc29\uc2dd\uc744 SGD\uac00 \uc544\ub2cc Adam\uc744 \uc0ac\uc6a9\ud558\uc5ec \uc815\ud655\ub3c4\ub97c \ud5a5\uc0c1\uc2dc\ucf1c \ubcf4\uaca0\uc2b5\ub2c8\ub2e4. \uc740\ub2c9\uce35\uc774 \ucd94\uac00 \ub418\uc5c8\uc73c\ubbc0\ub85c \ud65c\uc131\ud654 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=7805\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Model \ud655\uc7a5\uacfc \uac00\uc911\uce58\uac12 \ubcc0\uacbd\uc744 \ud1b5\ud55c \uc608\uce21 \uc815\ud655\ub3c4 \ud5a5\uc0c1&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[132],"tags":[],"class_list":["post-7805","post","type-post","status-publish","format-standard","hentry","category-deep-machine-learning"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/7805","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7805"}],"version-history":[{"count":11,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/7805\/revisions"}],"predecessor-version":[{"id":9387,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/7805\/revisions\/9387"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7805"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7805"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}