""#line:3
import numpy as np #line:4
import cv2 #line:5
import matplotlib .pyplot as plt #line:6
from keras .preprocessing .image import ImageDataGenerator #line:8
from keras .models import model_from_json #line:9
np .set_printoptions (suppress =True )#line:10
rename =True #line:19
names =['Elegant','Romantic','Ethnic','Country','Active','Mannish','Futurism','Sophisticated']#line:21
order =[5 ,6 ,7 ,0 ,1 ,2 ,3 ,4 ]#line:24
rotation_range =2 #line:27
width_shift_range =0.02 #line:28
height_shift_range =0.02 #line:29
channel_shift_range =40.0 #line:30
shear_range =0.02 #line:31
zoom_range =[1.0 ,1.1 ]#line:32
horizontal_flip =True #line:33
vertical_flip =False #line:34
batch_size =1 #line:37
average_num =10 #line:40
img_save =False #line:43
g_size =3 #line:46
logo_file ='nadera.png'#line:48
QR_file ='QR.png'#line:49
def show (OOO0O00OOO00O00OO ,name ='_'):#line:51
    plt .figure (figsize =(8 ,8 ))#line:52
    if np .max (OOO0O00OOO00O00OO )>1 :#line:53
        OOO0O00OOO00O00OO =np .array (OOO0O00OOO00O00OO ,dtype =int )#line:54
        plt .imshow (OOO0O00OOO00O00OO ,vmin =0 ,vmax =255 )#line:55
    else :#line:56
        plt .imshow (OOO0O00OOO00O00OO ,vmin =0 ,vmax =1 )#line:57
    plt .gray ()#line:58
    if img_save :#line:59
        plt .savefig (name +'.png')#line:60
    else :#line:61
        plt .show ()#line:62
    plt .close ()#line:63
class tool_nadera :#line:80
    def __init__ (O0OOO0O0OO0OO0O0O ,OO000OOOO000O0000 ,OO0OOOOO00OO00000 ):#line:81
        print ('Loading nadera model...',end ='')#line:88
        OOO00000OOO00O0OO =open (OO000OOOO000O0000 ,'r')#line:89
        O0000O00OO000O00O =OOO00000OOO00O0OO .read ()#line:90
        OOO00000OOO00O0OO .close ()#line:91
        print ('Done.')#line:92
        print ('Loading nadera weights...',end ='')#line:94
        O0OOO0O0OO0OO0O0O .model =model_from_json (O0000O00OO000O00O )#line:95
        O0OOO0O0OO0OO0O0O .model .load_weights (OO0OOOOO00OO00000 )#line:96
        O0OOO0O0OO0OO0O0O .model .trainable =False #line:97
        print ('Done.')#line:100
        class O00O000O0O0000OO0 (ImageDataGenerator ):#line:105
            def __init__ (OO0OO0O000O0OOO0O ,*O0O0O0OO0O00OO000 ,**O0OO0O0O0O000O0OO ):#line:106
                super ().__init__ (*O0O0O0OO0O00OO000 ,**O0OO0O0O0O000O0OO )#line:107
            def make_line (O0O0OOOO000OO00OO ,OOOOO00000OOOOOO0 ):#line:109
                O0O00OOO000OO00OO =cv2 .cvtColor (OOOOO00000OOOOOO0 ,cv2 .COLOR_RGB2GRAY )#line:111
                O0O00OOO000OO00OO =np .uint8 (O0O00OOO000OO00OO )#line:112
                O0OO0000O0O0000O0 =cv2 .Canny (O0O00OOO000OO00OO ,threshold1 =50 ,threshold2 =200 )#line:113
                O0OO0000O0O0000O0 =O0OO0000O0O0000O0 .reshape ((512 ,256 ,1 ))#line:114
                return O0OO0000O0O0000O0 #line:115
            def make_beta (OO000O00OOOOOO0OO ,O0O000O0000OO0OOO ):#line:117
                OO0OOO00O000O0O0O =cv2 .GaussianBlur (O0O000O0000OO0OOO ,(9 ,9 ),0 )#line:119
                O00O0000OOO000O00 =np .sum (OO0OOO00O000O0O0O ,axis =2 )#line:121
                O00O0000OOO000O00 [O00O0000OOO000O00 <252 *3 ]=255 #line:122
                O00O0000OOO000O00 [O00O0000OOO000O00 >=252 *3 ]=0 #line:123
                OOO0000000OOO0000 =np .ones ((5 ,5 ),np .uint8 )#line:125
                O00O0000OOO000O00 =cv2 .erode (O00O0000OOO000O00 ,OOO0000000OOO0000 ,iterations =1 )#line:126
                O00O0000OOO000O00 =O00O0000OOO000O00 .reshape ((512 ,256 ,1 ))#line:131
                return O00O0000OOO000O00 #line:132
            def make_blur (O000O00OOO0OOOOOO ,O0OO00O0OOO00O0O0 ):#line:134
                O00O00000O00OOOO0 =cv2 .GaussianBlur (O0OO00O0OOO00O0O0 ,(51 ,51 ),0 )#line:136
                return O00O00000O00OOOO0 #line:137
            def flow (O00OO00O0O0O00OO0 ,*OOO0O0O0O0OO0OOO0 ,**O0OOO0O0OOOOOOOOO ):#line:139
                OOO0000000000O00O =super ().flow (*OOO0O0O0O0OO0OOO0 ,**O0OOO0O0OOOOOOOOO )#line:140
                O0OOO000O0O0OOO0O =np .zeros ((batch_size ,512 ,256 ,1 ))#line:142
                OOOO000OOO0OO00OO =np .zeros ((batch_size ,512 ,256 ,1 ))#line:143
                OOO0000OO0O00O00O =np .zeros ((batch_size ,512 ,256 ,3 ))#line:144
                O00OOOOO0O0OOO0OO =np .zeros ((batch_size ,8 ))#line:145
                while True :#line:147
                    OO000O000000O00OO ,O0000O0OO00O0O00O =next (OOO0000000000O00O )#line:148
                    for OO00000000O0OOO00 ,O0OOOOO00OO0OOO0O in enumerate (OO000O000000O00OO ):#line:151
                        OOOO000OOO0OO00OO [OO00000000O0OOO00 ]=O00OO00O0O0O00OO0 .make_beta (O0OOOOO00OO0OOO0O )/255.0 #line:153
                        O0O00OO0OOOOOO00O =OOOO000OOO0OO00OO [OO00000000O0OOO00 ].reshape (OOOO000OOO0OO00OO [OO00000000O0OOO00 ].shape [:2 ])#line:154
                        OO0O00O00O0OOO0OO =np .random .uniform (-channel_shift_range ,channel_shift_range )#line:157
                        O0OOOOO00OO0OOO0O =np .clip (O0OOOOO00OO0OOO0O +OO0O00O00O0OOO0OO ,0 ,255 )#line:158
                        O0OOOOO00OO0OOO0O [:,:,0 ][O0O00OO0OOOOOO00O ==0 ]=255 #line:161
                        O0OOOOO00OO0OOO0O [:,:,1 ][O0O00OO0OOOOOO00O ==0 ]=255 #line:162
                        O0OOOOO00OO0OOO0O [:,:,2 ][O0O00OO0OOOOOO00O ==0 ]=255 #line:163
                        O0OOO000O0O0OOO0O [OO00000000O0OOO00 ]=O00OO00O0O0O00OO0 .make_line (O0OOOOO00OO0OOO0O )/255.0 #line:165
                        OOO0000OO0O00O00O [OO00000000O0OOO00 ]=O00OO00O0O0O00OO0 .make_blur (O0OOOOO00OO0OOO0O )/255.0 #line:166
                        O00OOOOO0O0OOO0OO [OO00000000O0OOO00 ]=O0000O0OO00O0O00O [OO00000000O0OOO00 ]#line:167
                    yield [O0OOO000O0O0OOO0O ,OOOO000OOO0OO00OO ,OOO0000OO0O00O00O ],O00OOOOO0O0OOO0OO #line:169
        O0OOO0O0OO0OO0O0O .MIDG =O00O000O0O0000OO0 (rescale =1.0 ,rotation_range =rotation_range ,width_shift_range =width_shift_range ,height_shift_range =height_shift_range ,shear_range =shear_range ,zoom_range =zoom_range ,horizontal_flip =horizontal_flip ,vertical_flip =vertical_flip ,)#line:181
    def do_nadera (OOOOOO00OOOO0000O ,O0OO0O00OO0O00O0O ,OO0000000OOO0O000 ):#line:185
        OO0O00OO0O00O0OOO =np .array ([O0OO0O00OO0O00O0O ])#line:188
        O0O00OO0OOOO0O0OO =[[0 for O0OOO000000O00OO0 in range (8 )]for O00O0O0OO0O0O0OO0 in range (len (OO0O00OO0O00O0OOO ))]#line:192
        O0O00OO0OOOO0O0OO =np .array (O0O00OO0OOOO0O0OO )#line:193
        '''
        #======================================
        # 生成器の確認
        #======================================
        #生成器に1枚だけ入れる
        gen_test = self.MIDG.flow(np.array([x_test[0]]), np.array([y_train[0]]), batch_size=batch_size)
        
        #5*5で生成して確認
        gen_ims_line = []
        gen_ims_beta = []
        gen_ims_blur = []
        for i in range(g_size**2):
            x_tmp, y_tmp = next(gen_test)
            gen_ims_line.append(deepcopy(x_tmp[0][0].reshape((512, 256))))
            gen_ims_beta.append(deepcopy(x_tmp[1][0].reshape((512, 256))))
            gen_ims_blur.append(deepcopy(x_tmp[2][0]))
            #print(y_tmp[0])
        
        stacks_line = []
        for i in range(g_size):
            stack = np.concatenate(gen_ims_line[g_size*i:g_size*(i + 1)], axis=1)
            stacks_line.append(stack)
        stacks_line = np.concatenate(stacks_line, axis=0)
        show(stacks_line, name='stacks_line')
        
        stacks_beta = []
        for i in range(g_size):
            stack = np.concatenate(gen_ims_beta[g_size*i:g_size*(i + 1)], axis=1)
            stacks_beta.append(stack)
        stacks_beta = np.concatenate(stacks_beta, axis=0)
        show(stacks_beta, name='stacks_beta')
        
        stacks_blur = []
        for i in range(g_size):
            stack = np.concatenate(gen_ims_blur[g_size*i:g_size*(i + 1)], axis=1)
            stacks_blur.append(stack)
        stacks_blur = np.concatenate(stacks_blur, axis=0)
        show(stacks_blur, name='stacks_blur')
        '''#line:234
        for OOO000OOO0O00OO0O in range (len (OO0O00OO0O00O0OOO [:])):#line:238
            O000OO0OO0OO00OOO =OOOOOO00OOOO0000O .MIDG .flow (np .array ([OO0O00OO0O00O0OOO [OOO000OOO0O00OO0O ]]),np .array ([O0O00OO0OOOO0O0OO [OOO000OOO0O00OO0O ]]),batch_size =batch_size )#line:241
            if np .min (OO0O00OO0O00O0OOO [OOO000OOO0O00OO0O ])==255 :#line:254
                O000O0OO000OOO0O0 =np .array ([np .zeros (len (names ))],float )#line:255
            else :#line:256
                O000O0OO000OOO0O0 =OOOOOO00OOOO0000O .model .predict_generator (O000OO0OO0OO00OOO ,steps =average_num ,use_multiprocessing =False ,workers =1 )#line:257
            O000O0OO000OOO0O0 [O000O0OO000OOO0O0 <0.0 ]=0.0 #line:268
            O000O0OO000OOO0O0 [O000O0OO000OOO0O0 >0.7 ]=0.7 #line:269
            O000O0OO000OOO0O0 *=(100.0 /70.0 )#line:270
            O0O00OOOO00OOO0O0 =np .mean (O000O0OO000OOO0O0 ,axis =0 )#line:274
            O0OO0OOO000OOOO00 =np .std (O000O0OO000OOO0O0 ,axis =0 )#line:275
            """
            meanは0.0-1.0の８つの値
            """#line:280
            OO000OO000OO000OO =np .array (names )#line:282
            if rename :#line:284
                OO000OO000OO000OO =OO000OO000OO000OO [order ]#line:285
                O0O00OOOO00OOO0O0 =O0O00OOOO00OOO0O0 [order ]#line:286
                O0OO0OOO000OOOO00 =O0OO0OOO000OOOO00 [order ]#line:287
            print ('nadera end.')#line:289
            if OO0000000OOO0O000 =='values':#line:290
                return OO000OO000OO000OO ,O0O00OOOO00OOO0O0 ,O0OO0OOO000OOOO00 #line:291
            else :#line:292
                O00O00O000OO00OO0 =np .argmax (O0O00OOOO00OOO0O0 )#line:293
                return OO000OO000OO000OO [O00O00O000OO00OO0 ],O0O00OOOO00OOO0O0 [O00O00O000OO00OO0 ],O0OO0OOO000OOOO00 [O00O00O000OO00OO0 ]#line:294
if __name__ =='__main__':#line:300
    pass #line:302
