{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "11397531", "metadata": {}, "outputs": [], "source": [ "import json\n", "from glob import glob\n", "from tqdm import tqdm\n", "import os\n", "import shutil" ] }, { "cell_type": "code", "execution_count": 4, "id": "639a635c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "macaw-multimodal/synthetic-multi-images-multi-audio-relationship.jsonl\r\n", "macaw-multimodal/synthetic-multi-images-relationship.jsonl\r\n" ] } ], "source": [ "!ls macaw-multimodal/synthetic-*images*.jsonl" ] }, { "cell_type": "code", "execution_count": 5, "id": "230fda70", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['macaw-multimodal/synthetic-multi-images-relationship.jsonl',\n", " 'macaw-multimodal/synthetic-multi-images-multi-audio-relationship.jsonl']" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "files = glob('macaw-multimodal/synthetic-*images*.jsonl')\n", "files" ] }, { "cell_type": "code", "execution_count": 6, "id": "dbdd6fd6", "metadata": {}, "outputs": [], "source": [ "!mkdir filtered-blip-images" ] }, { "cell_type": "code", "execution_count": 9, "id": "fc2f5947", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100000it [00:01, 88185.31it/s]\n", "59400it [00:01, 52003.73it/s]\n" ] } ], "source": [ "images = []\n", "\n", "for f in files:\n", " with open(f) as fopen:\n", " for l in tqdm(fopen):\n", " l = json.loads(l)\n", " for f_ in l['filename']:\n", " if f_.endswith('.jpg'):\n", " images.append(f_)\n", "# break\n", "# img = l['image']\n", "# f_img = f'train2014/COCO_train2014_{img}'\n", "# if not os.path.exists(f_img):\n", "# continue\n", "# shutil.copyfile(f_img, os.path.join('filtered-llava-images', img))" ] }, { "cell_type": "code", "execution_count": 10, "id": "75ff4044", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "259400" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(images)" ] }, { "cell_type": "code", "execution_count": 18, "id": "dda18075", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 238135/238135 [17:04<00:00, 232.47it/s] \n" ] } ], "source": [ "for img in tqdm(list(set(images))):\n", " f = os.path.join('blip', img)\n", " folder = f.split('/')[1]\n", " os.makedirs(os.path.join('filtered-blip-images', folder), exist_ok = True)\n", " shutil.copyfile(f, os.path.join('filtered-blip-images', img))" ] }, { "cell_type": "code", "execution_count": 19, "id": "bbc499fe", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "12G\tfiltered-blip-images\r\n" ] } ], "source": [ "!du -hs filtered-blip-images" ] }, { "cell_type": "code", "execution_count": 20, "id": "29021779", "metadata": {}, "outputs": [], "source": [ "!~/7zz -v5g a filtered-blip-images.7z filtered-blip-images > /dev/null" ] }, { "cell_type": "code", "execution_count": 21, "id": "ac2eb144", "metadata": {}, "outputs": [], "source": [ "from huggingface_hub import HfApi\n", "api = HfApi()" ] }, { "cell_type": "code", "execution_count": 23, "id": "34db3d8d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "filtered-blip-images.7z.003\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "35049f783ad84ea0b66c3c45bd2718d9", "version_major": 2, "version_minor": 0 }, "text/plain": [ "filtered-blip-images.7z.003: 0%| | 0.00/747M [00:00