Browse Source

Merge 77cf421dce into bc07ce62c1

pull/100/merge
ShiYiming 2 years ago committed by GitHub
parent
commit
e4040e752b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      clip_interrogator.ipynb
  2. 26
      run_cli.py

36
clip_interrogator.ipynb

@ -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" "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", "cell_type": "code",
"execution_count": null, "execution_count": null,
@ -256,7 +290,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.9.5" "version": "3.8.5"
}, },
"orig_nbformat": 4, "orig_nbformat": 4,
"vscode": { "vscode": {

26
run_cli.py

@ -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 #!/usr/bin/env python3
import argparse import argparse
import csv import csv
@ -73,7 +75,8 @@ def main():
print(f'The folder {args.folder} does not exist!') print(f'The folder {args.folder} does not exist!')
exit(1) 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 = [] prompts = []
for file in files: for file in files:
image = Image.open(os.path.join(args.folder, file)).convert('RGB') image = Image.open(os.path.join(args.folder, file)).convert('RGB')
@ -81,15 +84,20 @@ def main():
prompts.append(prompt) prompts.append(prompt)
print(prompt) print(prompt)
if len(prompts): # 写入到本地文件 caption.txt 中
csv_path = os.path.join(args.folder, 'desc.csv') with open("/data/hdd1/shiym/competition/GitHubClone/diffusers/examples/custom_diffusion/real_reg/samples_girl/caption.txt", "w", encoding="utf-8") as f:
with open(csv_path, 'w', encoding='utf-8', newline='') as f: for prompt in prompts:
w = csv.writer(f, quoting=csv.QUOTE_MINIMAL) f.write(prompt + "\n")
w.writerow(['image', 'prompt'])
for file, prompt in zip(files, prompts): # if len(prompts):
w.writerow([file, prompt]) # 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__": if __name__ == "__main__":
main() main()

Loading…
Cancel
Save