๐Ÿ“’ [ TIL ] 2022.05.19_23์ผ์ฐจ # ์‚ฌ๋ฌผ์ธ์‹ ๋จธ์‹ ๋Ÿฌ๋‹(2)

๋ฌธ๋ช…์ฃผยท2022๋…„ 5์›” 19์ผ
0

[ 2022-05-19 (๋ชฉ) ์˜ค๋Š˜์˜ TIL ]

[ Today Project ]

  • ์‚ฌ๋ฌผ์ธ์‹ ๋จธ์‹ ๋Ÿฌ๋‹
    : ์ด๋ฒˆ ํ”„๋กœ์ ํŠธ๋Š” ํŒ€ํ”„๋กœ์ ํŠธ๋กœ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

[ Today Learn ]

  • ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ
  • ๊ฒŒ์‹œ๋ฌผ ํฌ์ŠคํŒ… ๋ฐ ๋ฆฌ์ŠคํŒ… ๊ฐœ๋ฐœ
  • ์•„๋‚˜์ฝ˜๋‹คํ™œ์šฉํ•œ ์‚ฌ๋ฌผ์ธ์‹ ๊ธฐ๋Šฅ

โœ๏ธ ๋‚ด๊ฐ€ ๋ฐฐ์šด๊ฒƒ, ์–ป์€๊ฒƒ

  • ์ด๋ฏธ์ง€ํŒŒ์ผ์„ ๋ฐ์ดํ„ฐ๋กœ ์ด๋™์‹œํ‚ฌ๋•Œ๋Š” 'formData'๋ฅผ ํ™œ์šฉํ•ด์•ผ ๊ฐ€๋Šฅํ•˜๋‹ค.

๐Ÿงฉ ์ ์šฉ์˜ˆ์‹œ

function uploading_files() {
        let file = files[0]; //์‹ค์ œ ํŒŒ์ผ
        let image = files[0].name; //ํŒŒ์ผ๋ช…
        let username = $("#input-username").val()
        console.log(username)

        let formData = new FormData();
        formData.append('file_give', file)
        formData.append('image_give', image)
        formData.append('username_give', username)
        console.log(formData)

        $.ajax({
            type: 'POST',
            url: '/content',
            processData: false,
            contentType: false,
            data: formData,
            success: function (response) {
                if (response['result'] == 'success') {
                    alert(response['msg'])
                    window.location.href = '/'
                } else {
                    alert(response['msg'])
                    window.location.reload()
                }
            }

๐Ÿงฉ ์ ์šฉ์˜ˆ์‹œ

  • ํ•™์Šต๋œ ๋ชจ๋ธ ์ €์žฅํ•˜๊ธฐ
    ๋ชจ๋ธ์€ ํฌ๊ฒŒ ๋ชจ๋ธ ์•„ํ‚คํ…์ฒ˜์™€ ๋ชจ๋ธ ๊ฐ€์ค‘์น˜๋กœ ๊ตฌ์„ฑ๋˜๋Š”๋ฐ, ๋ชจ๋ธ ๊ฐ€์ค‘์น˜๋Š” ์ž„์˜์˜ ๊ฐ’์œผ๋กœ ์ดˆ๊ธฐํ™”๋˜์–ด ์žˆ์ง€๋งŒ, ํ›ˆ๋ จ์…‹์œผ๋กœ ํ•™์Šตํ•˜๋ฉด์„œ ๊ฐฑ์‹ ๋œ๋‹ค. ๊ทธ ํ•™์Šต๋œ ๋ชจ๋ธ์„ Keras์—์„œ๋Š” save() ํ•จ์ˆ˜๋กœ โ€˜h5โ€™ํŒŒ์ผ ํ˜•์‹์œผ๋กœ ๋ชจ๋‘ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋‹ค.

  • ์‚ฌ๋ฌผ์ธ์‹๊ธฐ๋Šฅ
    ์šฐ๋ฆฌ ํŒ€์˜ ์‚ฌ๋ฌผ์ธ์‹ ์ฃผ์ œ๋Š” '๊ฐ•์•„์ง€ ์ข… ํŒ๋ณ„ํ•˜๊ธฐ' ์ด๋‹ค. ๋”ฐ๋ผ์„œ ๋งŽ์€ ๊ฐ•์•„์ง€ ์‚ฌ์ง„๋“ค์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•™์Šต์‹œ์ผœ ๊ฐ•์•„์ง€ ์ข…์„ ๊ตฌ๋ถ„ํ•ด์ฃผ๋Š” ๊ธฐ๋Šฅ์„ ๋งŒ๋“ค์—ˆ๋‹ค.

model = tf.keras.models.load_model('static/model/model.h5')
    test_url = f'static/img/post_contents/{filename}'
    test_generator = tf.keras.preprocessing.image.load_img(test_url, grayscale=False, color_mode="rgb",
                                                           target_size=(299, 299))
    input_arr = tf.keras.preprocessing.image.img_to_array(test_generator)
    input_arr = np.array([input_arr])
    input_arr /= 225.

    pred = model.predict(input_arr)
    pred2 = pred.argmax(axis=-1)
    dog_list = [''']
    dog_name = dog_list[pred2[0]]

์œ„์˜ ์—…๋กœ๋“œ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ์•„๋ž˜์™€ ๊ฐ™์€ drag&drop ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•˜์—ฌ ์‚ฌ์ง„์„ ์—…๋กœ๋“œ ํ•˜๊ฒŒ๋˜๋ฉด,

์•„๋ž˜์™€ ๊ฐ™์ด ํ•™์Šต๋œ ๊ฒƒ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๊ฐ•์•„์ง€์˜ ์ข…๋ฅ˜๋ฅผ ํŒ๋ณ„ํ•˜์—ฌ ๋ณด์—ฌ์ฃผ๊ฒŒ๋œ๋‹ค.

๐ŸŒฑ ๋Š๋‚€ ์ 

์ด๋ฒˆ์— ํŒ€์›๋“ค์ด ๋ชจ๋‘ ์ž˜ํ•˜๋Š” ํŒ€์›๋“ค์ด์—ฌ์„œ ํ™•์‹คํžˆ ์—ด์‹ฌํžˆ ํ•ด์•ผ๊ฒ ๋‹ค๋Š” ๋™๊ธฐ๋ถ€์—ฌ๊ฐ€๋˜๋Š”๊ฒƒ ๊ฐ™๋‹ค.
์ผ๋‹จ ์ด๋ฒˆ ํ”„๋กœ์ ํŠธ์—์„œ ํ”„๋ก ํŠธ์—”๋“œ๋ณด๋‹ค๋Š” ์ฃผ๋กœ ๋ฐฑ์—”๋“œ์™€ ์‚ฌ๋ฌผ์ธ์‹๊ธฐ๋Šฅ์„ ํ•˜๋Š”๋ฐ์— ๋” ํž˜์ผ๊ณ , ์ €๋ฒˆ ํ”„๋กœ์ ํŠธ๋ณด๋‹ค ๊นƒํ™œ์šฉ์„ ํ™•์‹คํžˆ ๋งŽ์ด ํ•ด๋ดค๋‹ค. ์—ญ์‹œ ํ•ด๋ณด๋‹ˆ๊นŒ ๊ฐ์ด ์žกํžˆ๋Š” ๊ฒƒ ๊ฐ™๋‹ค. ์ž์ฃผ์ž์ฃผ ํ‘ธ์‹œํ•˜๊ณ  ํ’€์„ ํ•ด์ค˜์•ผ ์ถฉ๋Œ์ด ๋งŽ์ด ์ผ์–ด๋‚˜์ง€ ์•Š๋Š”๊ฒƒ์„ ๊นจ๋‹ฌ์•˜๋‹ค.
ํ”„๋กœ์ ํŠธ๊ฐ€ ์ƒ๊ฐํ–ˆ๋˜ ๊ฒƒ๋ณด๋‹ค ๋นจ๋ฆฌ ๋๋‚˜๊ฒŒ ๋˜์„œ ๋‚ด์ผ์€ ์‚ฌ๋ฌผ์ธ์‹์˜ ์ •ํ™•๋„๋ฅผ ๋” ์˜ฌ๋ฆด ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ด์„œ ์ ์šฉ์‹œ์ผœ๋ด์•ผํ• ๊ฒƒ ๊ฐ™๋‹ค.
๊ทธ๋ฆฌ๊ณ  ์šฐ๋ฆฌํŒ€์ด ๋‘๋ฒˆ์งธ๋กœ ์˜ˆ์ •ํ–ˆ๋˜ ์‚ฌ๋ฌผ์ธ์‹์„ ์ด์šฉํ•ด์„œ ๋กค ์ฑ”ํ”ผ์–ธ์„ ๊ตฌ๋ถ„ํ•˜๋Š” ๊ฒƒ๋„ ๋”ฐ๋กœ ๋งŒ๋“ค์–ด๋ณผ ์˜ˆ์ •์ด๋‹ค.

๐ŸŽ ์ž์„ธํ•œ ์ฝ”๋“œ๋Š” Moonmoo ์— ๊ฒŒ์‹œํ–ˆ์Šต๋‹ˆ๋‹ค

profile
ํ•˜๋ฃจ ํ•œ๊ฑธ์Œ์”ฉ ๊พธ์ค€ํžˆ ๋‚˜์•„๊ฐ€๋Š” ๊ฐœ๋ฐœ์ž๐Ÿ™†โ€โ™€๏ธ https://github.com/Moonmooj

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

๊ด€๋ จ ์ฑ„์šฉ ์ •๋ณด