<jupyter_start><jupyter_text>================================我是分隔線======================================

從這裡以下都是我自己測試用亂打的東西，或者當剪貼簿使用，

執行99%會報錯，因為很多根本沒寫完整，可以不用管@@ ================================我是分隔線======================================

model讀寫測試<jupyter_code># model讀寫測試
import configparser
def fromConfig(session_name,value_name):
    conf = configparser.ConfigParser()
    conf.read("/content/drive/MyDrive/TibaMe/Phantom Captcher/pcserver_test/config.ini", encoding='utf-8')
    return [item[1] for item in conf.items(session_name) if item[0]==value_name][0]

# 基本測試(模型)：切換&讀寫&使用
# Tensorflow： .ckpt .pb
# Keras：   .h5
# Pytorch：  .pkl .pth .pt .t7

import torch
from torchvision import transforms
import torch.nn as nn
# import torch.optim as optim




def loadModel(model_name):
    if model_name.split('.')[-1] in ['pkl','pth','pt']:
        # model_ = 
        # model_.load_state_dict(torch.load(model_name))
        model_ = torch.load(model_name)
        return model_
print(fromConfig('Models','model_fitin'))
# model_fitin=loadModel(fromConfig('Models','model_fitin'))
model_fitin=loadModel("/content/drive/MyDrive/TibaMe/Phantom Captcher/Image_Harmonization_Datasets/DoveNet/checkpoints_/experiment_name_pretrain/latest_net_G.pth")
# model_fitin.eval()
print(model_fitin)

transform_ = transforms.ToTensor()
img_ = Image.open('fitin_test.png')
input_ = transform_(img_)
print(input_)

# output_ = model_fitin(input_)
# print(output_)<jupyter_output><empty_output><jupyter_text>================================我是分隔線======================================

刪重複測試<jupyter_code>import os
import re
from IPython.display import clear_output
import time

BASNetDS_dir_path="/content/drive/Shareddrives/幻影捕手/AI班團專_幻影捕手/資料集/BASNetDS"

dirlist_BASNetDS=sorted([ item for item in os.listdir(BASNetDS_dir_path) if '.' not in item])

regex_=re.compile(r'\(\d\)')
flag_=True
while flag_:
    str_=''
    for dirname_ in dirlist_BASNetDS:
        dirpath_=f"{BASNetDS_dir_path}/{dirname_}"
        n_=len(os.listdir(dirpath_))
        str_+=f'-{dirname_}({n_}/73157):\n'
        count_=0
        for filename_ in sorted(os.listdir(dirpath_)):
            if len(regex_.findall(filename_))>0:
                count_+=1
                filepath=f"{dirpath_}/'{filename_}'"
                temp_='x'
                temp_=os.system(f"rm -r {filepath}")
                str_+=f'\tdelete-{temp_} {filename_}\n'
        n_-=73157
        str_+=f'\t — {count_}(-{n_}={count_-n_})\n'
    clear_output()
    print(str_)
    print(f'#------------------------------------------')
    
    # time.sleep(5)
    flag_=False

# flag_=True
# while flag_:
    # dirname_=dirlist_BASNetDS[0]
    # dirpath_=f"{BASNetDS_dir_path}/{dirname_}"
    # n_=len(os.listdir(dirpath_))
    # str_+=f'-{dirname_}({n_}/73157):\n'
    # for filename_ in sorted(os.listdir(dirpath_)):
    #     filepath=f"{dirpath_}/{filename_}"
    #     if not os.path.exists(filepath.replace('png','jpg').replace('gt_aug_cm','im_aug_cm')):
    #         temp_=os.system(f"rm -r '{filepath}'")
    #         print(f'\tdelete-{temp_}\t{filename_}\t X')
    # dirname_=dirlist_BASNetDS[1]
    # dirpath_=f"{BASNetDS_dir_path}/{dirname_}"
    # n_=len(os.listdir(dirpath_))
    # str_+=f'-{dirname_}({n_}/73157):\n'
    # for filename_ in sorted(os.listdir(dirpath_)):
    #     filepath=f"{dirpath_}/{filename_}"
    #     if not os.path.exists(filepath.replace('png','jpg').replace('gt_aug_cm','im_aug_cm')):
    #         temp_=os.system(f"rm -r '{filepath}'")
    #         print(f'\tdelete-{temp_}\t X\t{filename_}')

    # time.sleep(5)
    # flag_=False<jupyter_output><empty_output><jupyter_text>================================我是分隔線======================================

刪減測試<jupyter_code>import os
import re
from IPython.display import clear_output
import time
import random
from PIL import Image

BASNetDS_dir_path="/content/drive/Shareddrives/幻影捕手/AI班團專_幻影捕手/資料集/BASNetDS/im_aug_cm"

i=os.listdir(f'{BASNetDS_dir_path}_small')
len_=15000-i
dirlist_BASNetDS=os.listdir(BASNetDS_dir_path)
random.shuffle(dirlist_BASNetDS)
dirlist_BASNetDS=dirlist_BASNetDS[:len_]
i=i-1
for filename_ in dirlist_BASNetDS:
    filepath=f"{BASNetDS_dir_path}/{filename_}"
    img_=Image.open(filepath)
    new_filepath=f"{BASNetDS_dir_path}_small/{filename_}"
    img_.save(new_filepath)
    filename_=filename_.replace('jpg','png')
    filepath=f"{BASNetDS_dir_path.replace('im_aug_cm','gt_aug_cm')}/{filename_}"
    img_=Image.open(filepath)
    new_filepath=f"{BASNetDS_dir_path}_small/{filename_.replace('jpg','png')}"
    img_.save(new_filepath)
    i+=1
    print(f"{i}/{15000}")
print('Done')<jupyter_output><empty_output><jupyter_text>================================我是分隔線======================================

DB 測試<jupyter_code>#from google.cloud import storage
#storage_client = storage.Client.from_service_account_json(f'phantomcaptcher-gcskey.json')
#bucket = storage_client.bucket('phantomcaptcher_bucket')
#dbname = f'DB/PCtestDB_sqlite/PCtestDB_sqlite.db'
#filename = f'DB/PCtestDB_sqlite/{filename}'
#blob = bucket.blob(filename)
##blob.delete()
#blob.upload_from_filename(storefile_)
##blob.make_public()
#file_url= blob.public_url


import sqlite3
conn = sqlite3.connect('PCtestDB_sqlite.db')
c = conn.cursor()

c.execute('DELETE FROM users')
conn.commit()
c.execute('DELETE FROM imgs')
conn.commit()

c.execute('SELECT * FROM users')
print('user:\n',c.fetchall())
c.execute('SELECT * FROM imgs')
print('img:\n',c.fetchall())

print('----------------')

c.execute('INSERT INTO users(user_id,user_password) values (?, ?)',('user_test','user_test'))
conn.commit()

print('----------------')

c.execute('SELECT * FROM users')
print('user:\n',c.fetchall())
c.execute('SELECT * FROM imgs')
print('img:\n',c.fetchall())<jupyter_output><empty_output><jupyter_text>================================我是分隔線======================================

??? 測試<jupyter_code>from IPython.display import clear_output
# clear_output()
!pip3 install boxx
clear_output()
%cd /content/drive/MyDrive/TibaMe/'Phantom Captcher'/pcserver_test
!ls -a
!pip3 install -r requirements.txt
clear_output()
!pip3 install -r requirements.txt
clear_output()

!python main_test.py
import sqlite3
import DBcontrol
# conn = sqlite3.connect('PCtestDB_sqlite.db',check_same_thread=False)
# c = conn.cursor()
# c.execute('SELECT * FROM imgs')
# print(c.fetchall())
print(DBcontrol.GetImgSnaps('img_userid','svwriting'))<jupyter_output><empty_output><jupyter_text>================================我是分隔線======================================

ScreenPoint 測試<jupyter_code>from IPython.display import clear_output
from PIL import Image,ImageChops
import cv2
import screenpoint
# !pip install screenpoint
clear_output()
screen_=cv2.imread('/content/screen.png',0)
view_=cv2.imread('/content/view.jpg',0)
view1_=cv2.imread('/content/view1.jpg',0)
view2_=cv2.imread('/content/view2.jpg',0)
view3_=cv2.imread('/content/view3.jpg',0)
view4_=cv2.imread('/content/view4.jpg',0)
center_ = screenpoint.project(view_, screen_)
def dist_(point1,point2):
  return ((point1[0]-point2[0])**2+(point1[1]-point2[1])**2)**0.5
left_top = screenpoint.project(view1_, screen_)
right_top = screenpoint.project(view2_, screen_)
left_down = screenpoint.project(view3_, screen_)
right_down = screenpoint.project(view4_, screen_)
# w_=(center_[0]-left_top[0])*4
# h_=(left_top[1]-center_[1])*4
# range=(w_,h_)
# print(center_)
# print(left_top)
# print(right_top)
# print(left_down)
# print(right_down)
print(dist_(left_top,right_top))
print(dist_(left_down,right_down))
print(dist_(left_top,left_down))
print(dist_(right_top,right_down))
# print(range)<jupyter_output><empty_output><jupyter_text><jupyter_code>from PIL import Image
import requests
snap_=Image.open(requests.get("https://storage.googleapis.com/phantomcaptcher_bucket/imgs/img_snap/user_test-20210220-222355-267481.png", stream=True).raw)
object_=Image.open(requests.get("https://storage.googleapis.com/phantomcaptcher_bucket/imgs/img_object/user_test-20210220-222355-267481.png", stream=True).raw)
mask_=Image.open(requests.get("https://storage.googleapis.com/phantomcaptcher_bucket/imgs/img_mask/user_test-20210220-222355-267481.png", stream=True).raw)

object_1=object_[y:y+h, x:x+w]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21052010850336125, 'fraction_numerical': 0.01898808821795023, 'mean_word_length': 4.852311939268461, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 30, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '560158', 'license': 'MIT', 'n_tokens_mistral': 3366, 'n_tokens_neox': 3261, 'n_words': 376, 'path': 'ipynb/pc_test.ipynb', 'repo_name': 'svwriting/PhantomCaptcher', 'size': '8479'}