@@ -513,19 +513,17 @@ def config_filter(config):
513513 pass
514514
515515 # 处理旧版插件保存的错误参数问题
516- #print("-------处理错误-------")
517- #print(new_config)
518- print ("-------处理错误-------" )
516+ print ("-------错误参数纠正-------" )
519517 found_tabs = []
520518 fixed_config = {}
521519 for param in new_config .keys ():
522- res = re .match ("state-ext-control-net-txt2img_ ([0-9]+)-(.+)" ,param )
520+ res = re .match ("state-ext-control-net-(txt2img|img2img)_ ([0-9]+)-(.+)" ,param )
523521 if (res != None ):
524- if (res .group (2 ) not in ["presets" ,"preprocessor" ,"model" ]):
522+ if (res .group (3 ) not in ["presets" ,"preprocessor" ,"model" ]):
525523 try :
526- found_tabs .index (res .group (1 ))
524+ found_tabs .index (res .group (2 ))
527525 except ValueError :
528- found_tabs .append (res .group (1 ))
526+ found_tabs .append (res .group (2 ))
529527
530528 for param in new_config .keys ():
531529
@@ -536,30 +534,36 @@ def config_filter(config):
536534 target_word = str (res .group ()).replace (res .group (1 ),key )
537535 new_param = re .sub ("[-_](model|models|checkpoint|checkpoints)($|[_-])" , target_word , param )
538536 fixed_config [new_param ] = new_config [param ]
539-
537+
540538 # 纠正编号
541- res = re .match ("state-ext-control-net-txt2img_ ([0-9]+)-(.+)" ,param )
539+ res = re .match ("state-ext-control-net-(txt2img|img2img)_ ([0-9]+)-(.+)" ,param )
542540 if (res != None ):
543- if (res .group (1 ) != "0" and res .group (2 ) not in ["presets" ,"preprocessor" ,"model" ]):
544- tab_num = int (res .group (1 ))
545- if (tab_num % 3 == 0 ):
546- try :
547- found_tabs .index (str (tab_num / 3 ))
548- # 如果是9 如果发现3的位置有参数,就还需要检查一下1
549- if (tab_num == 9 ):
550- found_tabs .index ("1" )
551- except ValueError :
552- new_key = f"state-ext-control-net-txt2img_{ int (tab_num / 3 )} -{ res .group (2 )} "
541+ tab_num = int (res .group (2 ))
542+ if (res .group (2 ) != "0" and tab_num % 3 == 0 ):
543+ try :
544+ found_tabs .index (str (tab_num / 3 ))
545+ # 如果是9 如果发现3的位置有参数,就还需要检查一下1
546+ if (tab_num == 9 ):
547+ found_tabs .index ("1" )
548+ except ValueError :
549+ new_key = f"state-ext-control-net-{ res .group (1 )} _{ int (tab_num / 3 )} -{ res .group (3 )} "
550+ # 这三个选项,旧版是js控制会有序号问题,新版本py控制没有序号问题,所以这里判断纠正之后的位置有没有值,有的话就不动。
551+ if (res .group (3 ) in ["presets" ,"preprocessor" ,"model" ]):
552+ #print(param)
553+ if (new_config .get (new_key ,None ) == None ):
554+ fixed_config [new_key ] = new_config [param ]
555+ print (f" { param } 改为 { new_key } " )
556+ continue
557+ else :
553558 fixed_config [new_key ] = new_config [param ]
554559 print (f" { param } 改为 { new_key } " )
555560 continue
556561
557562 # 其余参数照搬
558563 fixed_config [param ] = new_config [param ]
559564
560- #print("-------处理错误-------")
561565 #print(fixed_config)
562- print ("-------处理错误-------" )
566+ # print("-------处理错误-------")
563567
564568 new_config = fixed_config
565569 return new_config
0 commit comments