{ "cells": [ { "cell_type": "markdown", "id": "7ad7df84", "metadata": {}, "source": [ "# __텍스트로 이미지 검색하기__" ] }, { "cell_type": "markdown", "id": "0ed4d1cf-5b88-442c-aeb5-1ad3ab50b8a7", "metadata": {}, "source": [ "- 튜토리얼 난이도: ★★☆☆☆\n", "- 읽는데 걸리는 시간: 7분\n", "- 사용 언어: [SQL](https://ko.wikipedia.org/wiki/SQL) (100%)\n", "- 실행 파일 위치: tutorial/thanosql_search/search_image_by_text.ipynb\n", "- 참고 문서: [Unsplash Dataset - Lite](https://unsplash.com/data), [Learning Transferable Visual Models From Natural Language Supervision](https://arxiv.org/abs/2103.00020)" ] }, { "cell_type": "markdown", "id": "c8ddaa24-2d1e-4991-b342-768bc6ee566f", "metadata": {}, "source": [ "## 튜토리얼 소개\n", "\n", "
자연어를 컴퓨터가 이해하려면 자연어를 수치화 해야 합니다. 최근 BERT나 GPT-3와 같은 사전학습 모델에 대한 연구가 활발히 이루어지고 있으며, 주목할 만한 성과를 보여주고 있습니다. 이러한 모델들은 자가 학습(Self-Supervised Learning)을 기반으로 각 문장들의 의미를 파악하고 유사한 의미를 갖는 각 문장들을 가깝게 위치하도록 저차원 공간에 수치화하여 표현합니다. 문장 간의 순서를 무작위로 섞거나 일부 단어를 마스킹하는 방식 등을 이용해 각 문장/문맥의 참/거짓 여부를 판단함으로써 라벨링 작업이 없어도 학습이 가능하도록 지원합니다.
\n", "👉 Unsplash는 20만 명 이상의 사진가들이 참여한 이미지들을 AI를 위한 데이터 세트로 무료로 공개했습니다. Unsplash Dataset - Lite는 25,000 장의 자연을 테마로한 이미지로 구성되어 있으며, 25,000 개의 키워드를 함께 제공합니다.
\n", "\n", " | photo_id | \n", "image_path | \n", "photo_image_url | \n", "photo_description | \n", "ai_description | \n", "
---|---|---|---|---|---|
0 | \n", "XMyPniM9LF0 | \n", "thanosql-dataset/unsplash_data/XMyPniM9LF0.jpg | \n", "https://images.unsplash.com/uploads/1411949294... | \n", "Woman exploring a forest | \n", "woman walking in the middle of forest | \n", "
1 | \n", "rDLBArZUl1c | \n", "thanosql-dataset/unsplash_data/rDLBArZUl1c.jpg | \n", "https://images.unsplash.com/photo-141633941111... | \n", "Succulents in a terrarium | \n", "succulent plants in clear glass terrarium | \n", "
2 | \n", "cNDGZ2sQ3Bo | \n", "thanosql-dataset/unsplash_data/cNDGZ2sQ3Bo.jpg | \n", "https://images.unsplash.com/photo-142014251503... | \n", "Rural winter mountainside | \n", "rocky mountain under gray sky at daytime | \n", "
3 | \n", "iuZ_D1eoq9k | \n", "thanosql-dataset/unsplash_data/iuZ_D1eoq9k.jpg | \n", "https://images.unsplash.com/photo-141487280988... | \n", "Poppy seeds and flowers | \n", "red common poppy flower selective focus phography | \n", "
4 | \n", "BeD3vjQ8SI0 | \n", "thanosql-dataset/unsplash_data/BeD3vjQ8SI0.jpg | \n", "https://images.unsplash.com/photo-141700759404... | \n", "Silhouette near dark trees | \n", "trees during night time | \n", "
unsplash_data 테이블은 아래와 같은 정보를 담고 있습니다.
\n", "텍스트-이미지 검색 알고리즘은 학습에 오랜 시간이 걸리고 총 4억 개의 데이터 세트로 사전 학습된 모델을 사용하기 때문에 \"BUILD MODEL\" 쿼리 구문을 이용한 학습 과정을 본 튜토리얼에서는 생략합니다. 위에서 지정한 tutorial_search_clip 모델은 베이스 알고리즘으로 CLIP을 사용한 사전학습 된 모델을 가져와서 사용하게 됩니다. \"CONVERT USING\" 쿼리 구문을 실행하게 되면 사용자가 옵션으로 지정한 이름 (default: 'convert_result')으로 이미지가 수치화 된 컬럼이 자동으로 생성이 되며, \"SEARCH IMAGE\" 쿼리 구문을 실행하게 되면 사용자가 옵션으로 지정한 이름 (default: 'search_result')으로 이미지 유사도 컬럼이 자동으로 생성 됩니다.
\n", "\n", " | photo_id | \n", "image_path | \n", "photo_image_url | \n", "photo_description | \n", "ai_description | \n", "convert_result | \n", "
---|---|---|---|---|---|---|
0 | \n", "XMyPniM9LF0 | \n", "thanosql-dataset/unsplash_data/XMyPniM9LF0.jpg | \n", "https://images.unsplash.com/uploads/1411949294... | \n", "Woman exploring a forest | \n", "woman walking in the middle of forest | \n", "[b'\\xf4', b'\\xc6', b'2', b'\\xbe', b'\\xb1', b'\"... | \n", "
1 | \n", "rDLBArZUl1c | \n", "thanosql-dataset/unsplash_data/rDLBArZUl1c.jpg | \n", "https://images.unsplash.com/photo-141633941111... | \n", "Succulents in a terrarium | \n", "succulent plants in clear glass terrarium | \n", "[b'F', b'\\x08', b'\\xbf', b'\\xbe', b'\\xc5', b'\\... | \n", "
2 | \n", "cNDGZ2sQ3Bo | \n", "thanosql-dataset/unsplash_data/cNDGZ2sQ3Bo.jpg | \n", "https://images.unsplash.com/photo-142014251503... | \n", "Rural winter mountainside | \n", "rocky mountain under gray sky at daytime | \n", "[b'G', b'\\x07', b'\\xb8', b'\\xbe', b'C', b'\\x93... | \n", "
3 | \n", "iuZ_D1eoq9k | \n", "thanosql-dataset/unsplash_data/iuZ_D1eoq9k.jpg | \n", "https://images.unsplash.com/photo-141487280988... | \n", "Poppy seeds and flowers | \n", "red common poppy flower selective focus phography | \n", "[b'H', b'\\x19', b'\\xae', b'<', b'=', b'\\xbe', ... | \n", "
4 | \n", "BeD3vjQ8SI0 | \n", "thanosql-dataset/unsplash_data/BeD3vjQ8SI0.jpg | \n", "https://images.unsplash.com/photo-141700759404... | \n", "Silhouette near dark trees | \n", "trees during night time | \n", "[b'\\xaa', b'\\x8c', b'\\x88', b'\\xbe', b'\\xbb', ... | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
24963 | \n", "c7OrOMxrurA | \n", "thanosql-dataset/unsplash_data/c7OrOMxrurA.jpg | \n", "https://images.unsplash.com/photo-159300793778... | \n", "None | \n", "black metal fence during daytime | \n", "[b'N', b'\\x88', b'\\n', b'\\xbe', b'p', b'\\xcf',... | \n", "
24964 | \n", "15IuQ5a0Qwg | \n", "thanosql-dataset/unsplash_data/15IuQ5a0Qwg.jpg | \n", "https://images.unsplash.com/photo-159296761254... | \n", "Pearl earrings and seashells | \n", "white and brown seashell on white surface | \n", "[b':', b'/', b'\\xa1', b'\\xbe', b'\\xf4', b'\\xbb... | \n", "
24965 | \n", "w8nrcXz8pwk | \n", "thanosql-dataset/unsplash_data/w8nrcXz8pwk.jpg | \n", "https://images.unsplash.com/photo-159299937329... | \n", "None | \n", "leopard on brown tree trunk during daytime | \n", "[b'\\x96', b'i', b'\\x96', b'=', b'\\xb6', b'\\x96... | \n", "
24966 | \n", "n1jHrRhehUI | \n", "thanosql-dataset/unsplash_data/n1jHrRhehUI.jpg | \n", "https://images.unsplash.com/photo-159192792878... | \n", "Floral truck in the streets of Rome | \n", "woman in beige coat and white hat standing on ... | \n", "[b'\\x82', b'\\xf0', b'c', b'=', b'`', b'e', b'm... | \n", "
24967 | \n", "Ic74ACoaAX0 | \n", "thanosql-dataset/unsplash_data/Ic74ACoaAX0.jpg | \n", "https://images.unsplash.com/photo-159240763188... | \n", "None | \n", "green plants on brown rocky mountain under blu... | \n", "[b'U', b'\\x19', b'%', b'\\xbe', b'!', b'Y', b'+... | \n", "
24968 rows × 6 columns
\n", "\n", " | photo_id | \n", "image_path | \n", "photo_image_url | \n", "photo_description | \n", "ai_description | \n", "convert_result | \n", "search_result | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "UMyfDjQ6Ep8 | \n", "thanosql-dataset/unsplash_data/UMyfDjQ6Ep8.jpg | \n", "https://images.unsplash.com/photo-157712719502... | \n", "None | \n", "black cat | \n", "[b'[', b'Z', b'\\xfe', b'>', b'\\x94', b'\\x95', ... | \n", "0.316560 | \n", "
1 | \n", "7XJ3d0xK444 | \n", "thanosql-dataset/unsplash_data/7XJ3d0xK444.jpg | \n", "https://images.unsplash.com/photo-157217373317... | \n", "None | \n", "black cat | \n", "[b'\\x9c', b'\\xec', b'\\x80', b'>', b'#', b'j', ... | \n", "0.311931 | \n", "
2 | \n", "m8HsSWh-y6E | \n", "thanosql-dataset/unsplash_data/m8HsSWh-y6E.jpg | \n", "https://images.unsplash.com/photo-156855266009... | \n", "simon the kitty. | \n", "silver tabby cat | \n", "[b'\\xff', b')', b'\\xa1', b'>', b'O', b'\\xe2', ... | \n", "0.310819 | \n", "
3 | \n", "6ST6S6i9IGM | \n", "thanosql-dataset/unsplash_data/6ST6S6i9IGM.jpg | \n", "https://images.unsplash.com/photo-1548620848-d... | \n", "The cutest black cat to wake up to on a Sunday... | \n", "close-up photography of bombay cat | \n", "[b'Z', b'`', b'x', b'>', b'\\x83', b'E', b'\\x15... | \n", "0.310214 | \n", "
4 | \n", "aFyD5aWKu6k | \n", "thanosql-dataset/unsplash_data/aFyD5aWKu6k.jpg | \n", "https://images.unsplash.com/photo-157850934606... | \n", "None | \n", "black cat | \n", "[b'\\xc6', b'\\x97', b'V', b'>', b'\\x0f', b'@', ... | \n", "0.309158 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
995 | \n", "VQ41v-gnd1M | \n", "thanosql-dataset/unsplash_data/VQ41v-gnd1M.jpg | \n", "https://images.unsplash.com/photo-158956048611... | \n", "None | \n", "purple smoke in black background | \n", "[b'\\xb7', b'\\xba', b'\\x16', b'>', b'G', b'l', ... | \n", "0.221887 | \n", "
996 | \n", "AtSgtZcxZFc | \n", "thanosql-dataset/unsplash_data/AtSgtZcxZFc.jpg | \n", "https://images.unsplash.com/photo-150329107570... | \n", "In the Smoke of Thinking | \n", "None | \n", "[b'\\xa8', b'\\xa7', b'\\xb3', b'\\xbc', b'\\xd4', ... | \n", "0.221874 | \n", "
997 | \n", "XzOMokbcp0Q | \n", "thanosql-dataset/unsplash_data/XzOMokbcp0Q.jpg | \n", "https://images.unsplash.com/photo-157616182589... | \n", "None | \n", "green-leafed plant during daytime | \n", "[b'\\xd8', b'\\x94', b'\\xc1', b'\\xbd', b'T', b'\\... | \n", "0.221858 | \n", "
998 | \n", "aWcJuh1mUhc | \n", "thanosql-dataset/unsplash_data/aWcJuh1mUhc.jpg | \n", "https://images.unsplash.com/photo-1544460671-b... | \n", "None | \n", "brown tabby cat on bed | \n", "[b',', b'\\x9a', b'Y', b'>', b'\\xf4', b'\\x93', ... | \n", "0.221827 | \n", "
999 | \n", "Zs6T2rub2zw | \n", "thanosql-dataset/unsplash_data/Zs6T2rub2zw.jpg | \n", "https://images.unsplash.com/photo-158179166724... | \n", "None | \n", "green pine trees covered with snow | \n", "[b'?', b'\\x8e', b'\\x1c', b'\\xbf', b'^', b'\\xa4... | \n", "0.221822 | \n", "
1000 rows × 7 columns
\n", "\n", " | image_path | \n", "search_result | \n", "
---|---|---|
0 | \n", "thanosql-dataset/unsplash_data/UMyfDjQ6Ep8.jpg | \n", "0.316560 | \n", "
1 | \n", "thanosql-dataset/unsplash_data/7XJ3d0xK444.jpg | \n", "0.311931 | \n", "
2 | \n", "thanosql-dataset/unsplash_data/m8HsSWh-y6E.jpg | \n", "0.310819 | \n", "
3 | \n", "thanosql-dataset/unsplash_data/6ST6S6i9IGM.jpg | \n", "0.310214 | \n", "
4 | \n", "thanosql-dataset/unsplash_data/aFyD5aWKu6k.jpg | \n", "0.309158 | \n", "
이 쿼리는 위의 쿼리와 합쳐 세 단계로 구성됩니다.
\n", "ThanoSQL을 활용해 나만의 모델을 만들거나, 나의 서비스에 적용하는데 어려움이 있다면 언제든 아래로 문의주세요😊
\n", "텍스트-이미지 검색 모델 구축 관련 문의: contact@smartmind.team
\n", "