[FF7PC]FF7 SYW V3, Battle, world map and fields with ERSGAN (WIP)

  • Thread starter Thread starter satsuki
  • Start date Start date
Status
Not open for further replies.
Yes it's with basicSR.
Some usefull informations
1)don't install nor use lmdb, it's a pain to install with python (on my windows at least) and it takes lots of ressources (and even in my classic no ssd drive, there's no benefits)
2)edit and use the extract_subimgs_single.py script for HQ set generation from your HQ sources
3)generate the LQ set with the imagemagik command : "convert.exe -filter box -resize 25%% #input# #output#"
4)Be sure all your HQ and LQ picture use the same color depth and setting (for that i use the imagemagik command :  "convert.exe #inptut# -define png:format=png24 #inpt#" , it ensure that all the png are compressed the same way and it's auto overwriting the source).
5)Make a set of verification of about 10% of the total pictures (for LQ anb HQ)
6)edit  the train_ESRGAN.json with your folders and to avoid a out of memory error :
      , "n_workers": 4
      , "batch_size": 8
I also set a "save_checkpoint_freq": 5000 to be able to stop/resume the training easily

for reference here's my edited python files (all the other files are as in the git without modification and i use python 3.6 and not anaconda):

extract_subimgs_single.py
Code: [Select]
Code:
import osimport os.pathimport sysfrom multiprocessing import Poolimport numpy as npimport cv2sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))from utils.progress_bar import ProgressBardef main():    """A multi-thread tool to crop sub imags."""    input_folder = "E:/ESRGANModel/ff7sources/"    save_folder = "E:/ESRGANModel/dataset/ff7hq/"    n_thread = 20    crop_sz = 480    step = 240    thres_sz = 48    compression_level = 0  # 3 is the default value in cv2    # CV_IMWRITE_PNG_COMPRESSION from 0 to 9. A higher value means a smaller size and longer    # compression time. If read raw images during training, use 0 for faster IO speed.    if not os.path.exists(save_folder):        os.makedirs(save_folder)        print('mkdir [{:s}] ...'.format(save_folder))    else:        print('Folder [{:s}] already exists. Exit...'.format(save_folder))        sys.exit(1)    img_list = []    for root, _, file_list in sorted(os.walk(input_folder)):        path = [os.path.join(root, x) for x in file_list]  # assume only images in the input_folder        img_list.extend(path)    def update(arg):        pbar.update(arg)    pbar = ProgressBar(len(img_list))    pool = Pool(n_thread)    for path in img_list:        pool.apply_async(worker,            args=(path, save_folder, crop_sz, step, thres_sz, compression_level),            callback=update)    pool.close()    pool.join()    print('All subprocesses done.')def worker(path, save_folder, crop_sz, step, thres_sz, compression_level):    img_name = os.path.basename(path)    img = cv2.imread(path, cv2.IMREAD_UNCHANGED)    n_channels = len(img.shape)    if n_channels == 2:        h, w = img.shape    elif n_channels == 3:        h, w, c = img.shape    else:        raise ValueError('Wrong image shape - {}'.format(n_channels))    h_space = np.arange(0, h - crop_sz + 1, step)    if h - (h_space[-1] + crop_sz) > thres_sz:        h_space = np.append(h_space, h - crop_sz)    w_space = np.arange(0, w - crop_sz + 1, step)    if w - (w_space[-1] + crop_sz) > thres_sz:        w_space = np.append(w_space, w - crop_sz)    index = 0    for x in h_space:        for y in w_space:            index += 1            if n_channels == 2:                crop_img = img[x:x + crop_sz, y:y + crop_sz]            else:                crop_img = img[x:x + crop_sz, y:y + crop_sz, :]            crop_img = np.ascontiguousarray(crop_img)            # var = np.var(crop_img / 255)            # if var > 0.008:            #     print(img_name, index_str, var)            cv2.imwrite(                os.path.join(save_folder, img_name.replace('.png', '_s{:03d}.png'.format(index))),                crop_img, [cv2.IMWRITE_PNG_COMPRESSION, compression_level])    return 'Processing {:s} ...'.format(img_name)if __name__ == '__main__':    main()
train_ESRGAN.json
Code: [Select]
Code:
{  "name": "RRDB_ESRGAN_x4_FF7" //  please remove "debug_" during training  , "use_tb_logger": true  , "model":"srragan"  , "scale": 4  , "gpu_ids": [0]  , "datasets": {    "train": {      "name": "FF7"      , "mode": "LRHR"      , "dataroot_HR": "E:/ESRGANModel/Dataset/ff7hq"      , "dataroot_LR": "E:/ESRGANModel/Dataset/ff7lq"      , "subset_file": null      , "use_shuffle": true      , "n_workers": 4      , "batch_size": 8      , "HR_size": 128      , "use_flip": true      , "use_rot": true    }   , "val": {      "name": "val_set14_part"      , "mode": "LRHR"      , "dataroot_HR": "E:/ESRGANModel/Dataset/ff7hqval"      , "dataroot_LR": "E:/ESRGANModel/Dataset/ff7lqval"   }  }  , "path": {    "root": "E:/ESRGANModel/InWorks"   // , "resume_state": "E:/ESRGANModel/InWorks/experiments/RRDB_ESRGAN_x4_FF7/training_state/15000.state"  //<=edit and uncomment to resume training    , "pretrain_model_G": "../experiments/pretrained_models/RRDB_PSNR_x4.pth"  }  , "network_G": {    "which_model_G": "RRDB_net" // RRDB_net | sr_resnet    , "norm_type": null    , "mode": "CNA"    , "nf": 64    , "nb": 23    , "in_nc": 3    , "out_nc": 3    , "gc": 32    , "group": 1  }  , "network_D": {    "which_model_D": "discriminator_vgg_128"    , "norm_type": "batch"    , "act_type": "leakyrelu"    , "mode": "CNA"    , "nf": 64    , "in_nc": 3  }  , "train": {    "lr_G": 1e-4    , "weight_decay_G": 0    , "beta1_G": 0.9    , "lr_D": 1e-4    , "weight_decay_D": 0    , "beta1_D": 0.9    , "lr_scheme": "MultiStepLR"    , "lr_steps": [50000, 100000, 200000, 300000]    , "lr_gamma": 0.5    , "pixel_criterion": "l1"    , "pixel_weight": 1e-2    , "feature_criterion": "l1"    , "feature_weight": 1    , "gan_type": "vanilla"    , "gan_weight": 5e-3    //for wgan-gp    // , "D_update_ratio": 1    // , "D_init_iters": 0    // , "gp_weigth": 10    , "manual_seed": 0    , "niter": 5e5    , "val_freq": 5e3  }  , "logger": {    "print_freq": 200    , "save_checkpoint_freq": 5000 //5e3  }}
 
Figured I'd post an update on that vapoursynth video/batch image tool here.

Though I'm not doing much original work in the first place, I'm almost done. I've made picture tutorials for installing CUDA and cuDNN from Nvidia's website, I've made a .bat file that installs and checks MXNet, I've made a .bat that downloads or updates the Super Resolution Zoo repo from Github, and I've made a python file that grabs all the neural net info files.

I just need to write some code in that python file that parses the NN info files and automatically inserts the correct syntax into a Vapoursynth script. Basically, without the script, you'd have to manually enter the path and correct arguments for the super resolution model you want, like:
Code: [Select]
Code:
sr_args = dict(model_filename=r'D:\CustomPrograms\VapourSynth64Portable\Models\Super-Resolution-Zoo\MSRN\MSRN_4x', device_id=0, up_scale=4, is_rgb_model=True, pad=None, crop=None, pre_upscale=False)
Which is tedious if you're trying to decide between 30+ different (pretrained) models. Anyway, I have plenty of time to finish that this weekend.
Thanks for your works, i think i'll have some fun with this ^^
 
Model training on its way...
Alright, so I installed BasicSR and ran it thru a test, despite your urging and considering that I do have a SSD drive, I still used the lmdb however ;-P

Also, I couldn't use your recommended (or the default) n_workers or batch_size settings. It bugged out on me, according to the posted issues on the github, this is a known issue on windows with torch, someone recommended that I set them to 0 and +1 total images respectively, and then it just ran thru them without hassle. I also had some weird issue with the progress_bar.py files as well. Where it checks for fps (line 41'ish) about it trying to divide by zero, so I simply altered the code there to check if the elapsed variable was 0 and if it was to skip the next line and instead set the fps to 0 by default.

I swiped thru just over 1.3K images in like 10 minutes, it was super fast actually (of course my 'high res' images were very small). I basically used the original backgrounds from FFVIII as my high-res images, so they were weren't exactly high res to begin with. But even still, if it only takes four times that long to swipe thru images four times bigger, that's still really fast. I'm thinking I did something wrong, but it spit out a model for me and I used it and it worked fine (although it sucked).

Was just curious what your strategy was for creating your own model. Are you using your current 'processes' upscaled images you created for FFVII as your high res images? Or are you using an entirely different set of images to generate your model?  Or did you do like I did with my first test, and use the original files as the high res?

I'm curious if applying this to a bunch of masks would also be helpful...??? What do you think?

This was neat though, not sure how I'll use this, but glad I have it to play with now :)
 
Last edited:
-progress_bar.py
>I removed it from the code, as the lmdb woring fast, no progresse needed for my tests ^^ (and i don't use it at end so...)

-I swiped thru just over 1.3K images in like 10 minutes
>I think you do something wrong, i own a gtx1060, the process uses about 90% of gpu (gpu is the bottleneck in basicSR) and it take about 3 minutes for 200 iter (and the learning process need to do 500 000 iter, so about 5.2days 24h/24h)

-the original backgrounds from FFVIII as my high-res images
>I used the team avalanche/jmp/jusete 3d art background as HQ picture, than downscale them and make a color reduction to get LQ picture (color reduction is a test as ff7 use paletted color pictures)

-I'm curious if applying this to a bunch of masks would also be helpful
>I don't think it'll helping anything, the best bet is that you found and use HQ ff8 art as close as possible as game picture (not sure my approach with 3d art will be usefull, it'a just an idea)
 
-I swiped thru just over 1.3K images in like 10 minutes
>I think you do something wrong, i own a gtx1060, the process uses about 90% of gpu (gpu is the bottleneck in basicSR) and it take about 3 minutes for 200 iter (and the learning process need to do 500 000 iter, so about 5.2days 24h/24h)
ya, I have the same card and I just compared the PSNR model with the one it produced for me and the results were identical actually, so I'm guessing it wasn't doing anything. I think this is related to the worker/batch arguments I modified to get it to 'work'. I'm guessing I'll have to try a linux install due to this torch issue in windows I suppose. What OS are you using?
 
-I swiped thru just over 1.3K images in like 10 minutes
>I think you do something wrong, i own a gtx1060, the process uses about 90% of gpu (gpu is the bottleneck in basicSR) and it take about 3 minutes for 200 iter (and the learning process need to do 500 000 iter, so about 5.2days 24h/24h)
As a side note, just for confirmation on how I did it. I put the 'original hi-res' images in the hqval folder, and my original downsized versions in the lqval folder. I then ran the extract_subimgs_single.py script on my hqval folder putting those files into the hr folder, and then downsized those and put them into my lr folder if that makes sense. I also ran that command you gave me on all the mages to makes sure they were all png 24 format.
 
That's not exactly the way it needed to be

1)Took your HQ pictures and run extract_subimgs_single.py on that folder
>Results in a ff8hq folder

2)Took the picture from  ff8hq folder and make a 25% downsize
>Results in a ff8lq folder

3)Copy about 10%/15% of pictures from  ff8hq folder
>Results in ff8hqval folder

4)Copy about 10%/15% of (the same than hq) pictures from  ff8lq folder
>Results in ff8lqval folder

5)"Normalize" with imagemagik

edit your train_esrgan.json file with your folders:
Code: [Select]
Code:
 , "datasets": {    "train": {      "name": "FF8"      , "mode": "LRHR"      , "dataroot_HR": "E:/ESRGANModel/Dataset/ff8hq"      , "dataroot_LR": "E:/ESRGANModel/Dataset/ff8lq"      , "subset_file": null      , "use_shuffle": true      , "n_workers": 4      , "batch_size": 8      , "HR_size": 128      , "use_flip": true      , "use_rot": true    }   , "val": {      "name": "val_set14_part"      , "mode": "LRHR"      , "dataroot_HR": "E:/ESRGANModel/Dataset/ff8hqval"      , "dataroot_LR": "E:/ESRGANModel/Dataset/ff8lqval"   }
launch the training ^^

As workers don't seems to work, try the values 1-2 or 2-4 instead of the original 8-16

My computer using windows 10 pro 1809 64 bits (corei7 8700k / 8go ram / gtx1060-6go)
here's my python config (default value without any mods, from ersgan use to basicSR):
1)install python 3.6.2 64bits
2)pip install scipy
3)pip install pillow
4)pip install numpy opencv-python
5)pip3 install http://download.pytorch.org/whl/cu90/torch-0.4.1-cp36-cp36m-win_amd64.whl
6)pip3 install torchvision
7)pip install numpy opencv-python
8)pip install tensorboardX
As i dont use lmdb i haven't put it here, but i installed it with a wheel file because of the well know vc++ 14 error (even if i installed the right buildtools)
 
okay, so if I'm understanding you correctly, I did exactly the same thing, except that I put all my files in the val folders (which I'm guessing would only make the process take longer in the end) and I didn't normalize my files, which again, I'm guessing would only have an effect on how my model ends up.

aside from that I didn't have scipy installed, which I just installed.

so I'm pretty confused as to why this isn't working for me, as was suggested in the notes on the github, I modified the worker/batch arguments and now the process seems to complete, but the model doesn't actually 'change', instead it just makes a copy of it from what I can tell and it completed the training super fast.

oh the joys of all of this... the best part is that if I figure this out, I can look forward to days of my computer doing nothing but crunching numbers just to end up with an even worse model than what I'm already using haha ;-P
 
The imagemagic normalization is only if you get a picture import error while runing training.
Have you tried the worker-batch to 1-2 or 2-4, i think the "0" worker you used make it bugs

"... the best part is that if I figure this out, I can look forward to days of my computer doing nothing but crunching numbers just to end up with an even worse model than what I'm already using"
That will probably be the same for my model training, but with a lot of luck maybe ....
 
Last edited:
Have you tried the worker-batch to 1-2 or 2-4, i think the "0" worker you used make it bugs
ya, anything above 0 makes it crash for some reason, we seem to have nearly identical systems, except that I'm using an i5, not that it should matter much though considering we're using our GPU's, which are identical. However I'm on Windows 7 and using Python 3.7.1. I'm pretty sure I ran into this issue before I even started using lmdb, so don't think it's related, but I'm not aware of the buildtools bug you were talking about which might be part of the problem I suppose. My guess is that the issue has more to do with either the OS differences or the Python version differences. I also just realized that I'm using PyTorch v1.0 not 0.4.1, but every attempt so far to downgrade has failed with  a 'not supported wheel on this platform' message :'(
 
Last edited:
Okay, I'm a big dummy and should of listened to you to begin with! :P
I disabled lmdb, and off it went without a hitch using the variables as they should be. (so much wasted time, I even installed python 3.6.7, 3.6.2, Anaconda...) haha
definitely taking a lot longer now...
 
Thanks for your works, i think i'll have some fun with this ^^

I lied about having plenty of time to finish it this weekend ;D. This is a WIP, but a functional WIP:

https://github.com/AlphaAtlas/vs_mxnet_helper/

You can format the imagemagik input to take (and write) a sequence of images easily enough, but among many other things, I need to figure out a script that can work through a whole directory recursively.
 
You can format the imagemagik input to take (and write) a sequence of images easily enough, but among many other things, I need to figure out a script that can work through a whole directory recursively.
I didn't really look at it much, but noticed you were using python and batch scripting, recursion is pretty simple tbh:

BATCH FILE RECURSION
Code: [Select]
Code:
@echo offfor /r %%f in (*.*) do ( echo The File: %%f echo The Directory: %%~pf echo The Filename: %%~nf echo The File Extension: %%~xf)
PYTHON RECURSION
Code: [Select]
Code:
src="C:/Windows"for root, dirnames, filenames in os.walk(src+"/"): for filename in fnmatch.filter(filenames, '*.*'):  infile=root+filename
 
I didn't really look at it much, but noticed you were using python and batch scripting, recursion is pretty simple tbh:

BATCH FILE RECURSION
Code: [Select]
Code:
@echo offfor /r %%f in (*.*) do ( echo The File: %%f echo The Directory: %%~pf echo The Filename: %%~nf echo The File Extension: %%~xf)
PYTHON RECURSION
Code: [Select]
Code:
src="C:/Windows"for root, dirnames, filenames in os.walk(src+"/"): for filename in fnmatch.filter(filenames, '*.*'):  infile=root+filename
Thanks, I may use that. The real trick is feeding that data to the ImageMagick plugin, which I can't just stick in another for loop IIRC.

http://www.vapoursynth.com/doc/plugins/imwri.html

I think I can physically move/rename all the images to a single directory with that script, let Vapoursynth do its thing on the nicely formatted images, then move the processed images back using the saved directory data once the script is done.
 
Last edited:
it's been a while, but imagemagick has it's own way of dealing with multiple files (I believe they are sequential, ie: image000.png, image001.png, image002.png) so if your files are number as such they are easy to manipulate. If you're moving files around that don't have names like that, you'll have to generate the names for the files and then likely keep a record as well (image000.png=somefile.png, image001.png=anotherfile.png, etc...) then when you're done manipulating the files in sequence, rename them again.
 
Finally some breakthrough for the pre-rendered backgrounds. The other method would have been to remake em in a 3D software which can take lot of work.
 
Game checked to the end.

To do before release:
-Need to find better filtering for 12 fields.
-Need to do some world map and battle fields optimisation.
-Need to wait the final alpha test from azertyuiop2 (ff7.fr) to spot bug or optimisation i havent seen.

After the release:
-Check if i can do a good videos upscale method
 
This looks so good. Just wonder exactly what pc version of FFVII do I need to make this mod work?
 
Status
Not open for further replies.
Back
Top