Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Generate caption in batch with order #100

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion clip_interrogator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,40 @@
"And if you're looking for more Ai art tools check out my [Ai generative art tools list](https://pharmapsychotic.com/tools.html).\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['182.jpg', '138.jpg', '116.jpg', '13.jpg', '140.jpg', '90.jpg', '131.jpg', '55.jpg', '144.jpg', '142.jpg', '43.jpg', '22.jpg', '64.jpg', '162.jpg', '16.jpg', '117.jpg', '159.jpg', '76.jpg', '96.jpg', '188.jpg', '9.jpg', '28.jpg', '14.jpg', '139.jpg', '66.jpg', '129.jpg', '171.jpg', '29.jpg', '123.jpg', '181.jpg', '191.jpg', '104.jpg', '71.jpg', '23.jpg', '175.jpg', '185.jpg', '168.jpg', '0.jpg', '156.jpg', '133.jpg', '119.jpg', '82.jpg', '89.jpg', '42.jpg', '50.jpg', '149.jpg', '7.jpg', '103.jpg', '134.jpg', '52.jpg', '72.jpg', '31.jpg', '107.jpg', '112.jpg', '20.jpg', '105.jpg', '75.jpg', '148.jpg', '163.jpg', '67.jpg', '85.jpg', '194.jpg', '93.jpg', '160.jpg', '48.jpg', '6.jpg', '32.jpg', '21.jpg', '110.jpg', '79.jpg', '146.jpg', '8.jpg', '19.jpg', '113.jpg', '173.jpg', '114.jpg', '166.jpg', '86.jpg', '141.jpg', '63.jpg', '102.jpg', '81.jpg', '45.jpg', '18.jpg', '147.jpg', '44.jpg', '165.jpg', '124.jpg', '145.jpg', '196.jpg', '100.jpg', '180.jpg', '46.jpg', '150.jpg', '73.jpg', '37.jpg', '39.jpg', '177.jpg', '58.jpg', '60.jpg', '70.jpg', '122.jpg', '186.jpg', '34.jpg', '91.jpg', '153.jpg', '2.jpg', '197.jpg', '62.jpg', '5.jpg', '115.jpg', '57.jpg', '151.jpg', '137.jpg', '25.jpg', '130.jpg', '83.jpg', '169.jpg', '12.jpg', '125.jpg', '77.jpg', '195.jpg', '128.jpg', '51.jpg', '88.jpg', '53.jpg', '157.jpg', '109.jpg', '132.jpg', '38.jpg', '59.jpg', '121.jpg', '174.jpg', '184.jpg', '98.jpg', '187.jpg', '101.jpg', '69.jpg', '30.jpg', '24.jpg', '36.jpg', '26.jpg', '27.jpg', '192.jpg', '154.jpg', '87.jpg', '95.jpg', '33.jpg', '127.jpg', '164.jpg', '1.jpg', '167.jpg', '80.jpg', '189.jpg', '193.jpg', '198.jpg', '108.jpg', '179.jpg', '135.jpg', '176.jpg', '152.jpg', '155.jpg', '40.jpg', '3.jpg', '106.jpg', '170.jpg', '92.jpg', '161.jpg', '78.jpg', '15.jpg', '97.jpg', '126.jpg', '136.jpg', '94.jpg', '118.jpg', '84.jpg', '54.jpg', '65.jpg', '56.jpg', '199.jpg', '68.jpg', '111.jpg', '74.jpg', '120.jpg', '35.jpg', '172.jpg', '178.jpg', '183.jpg', '17.jpg', '47.jpg', '10.jpg', '158.jpg', '11.jpg', '41.jpg', '99.jpg', '190.jpg', '49.jpg', '61.jpg', '4.jpg', '143.jpg']\n"
]
}
],
"source": [
"import os\n",
"files = [f for f in os.listdir(\"/data/hdd1/shiym/competition/GitHubClone/diffusers/examples/custom_diffusion/real_reg/samples_girl/images\") ]\n",
"print(files)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"folder_path = \"/data/hdd1/shiym/competition/GitHubClone/diffusers/examples/custom_diffusion/real_reg/samples_girl/images\"\n",
"\n",
"files = sorted([f for f in os.listdir(folder_path) if f.endswith(\".jpg\")])\n",
"\n",
"print(files)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -256,7 +290,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.5"
"version": "3.8.5"
},
"orig_nbformat": 4,
"vscode": {
Expand Down
26 changes: 17 additions & 9 deletions run_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# python run_cli.py -f /data/hdd1/shiym/competition/GitHubClone/diffusers/examples/custom_diffusion/real_reg/samples_girl/images -c ViT-L-14/openai -d cuda -m best

#!/usr/bin/env python3
import argparse
import csv
Expand Down Expand Up @@ -73,23 +75,29 @@ def main():
print(f'The folder {args.folder} does not exist!')
exit(1)

files = [f for f in os.listdir(args.folder) if f.endswith('.jpg') or f.endswith('.png')]

files = sorted([f for f in os.listdir(args.folder) if f.endswith('.jpg') or f.endswith('.png')])
prompts = []
for file in files:
image = Image.open(os.path.join(args.folder, file)).convert('RGB')
prompt = inference(ci, image, args.mode)
prompts.append(prompt)
print(prompt)

if len(prompts):
csv_path = os.path.join(args.folder, 'desc.csv')
with open(csv_path, 'w', encoding='utf-8', newline='') as f:
w = csv.writer(f, quoting=csv.QUOTE_MINIMAL)
w.writerow(['image', 'prompt'])
for file, prompt in zip(files, prompts):
w.writerow([file, prompt])
# 写入到本地文件 caption.txt 中
with open("/data/hdd1/shiym/competition/GitHubClone/diffusers/examples/custom_diffusion/real_reg/samples_girl/caption.txt", "w", encoding="utf-8") as f:
for prompt in prompts:
f.write(prompt + "\n")

# if len(prompts):
# csv_path = os.path.join(args.folder, 'desc.csv')
# with open(csv_path, 'w', encoding='utf-8', newline='') as f:
# w = csv.writer(f, quoting=csv.QUOTE_MINIMAL)
# w.writerow(['image', 'prompt'])
# for file, prompt in zip(files, prompts):
# w.writerow([file, prompt])

print(f"\n\n\n\nGenerated {len(prompts)} and saved to {csv_path}, enjoy!")
# print(f"\n\n\n\nGenerated {len(prompts)} and saved to {csv_path}, enjoy!")

if __name__ == "__main__":
main()