From 3d8d35095adef09cd9a8a53ff369058e3e8c1df6 Mon Sep 17 00:00:00 2001 From: sshinohs Date: Fri, 27 Jan 2023 13:39:45 +0900 Subject: [PATCH 01/17] test: black --- .github/workflows/black.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index df65bb5..5a17f1a 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -31,3 +31,4 @@ jobs: uses: lgeiger/black-action@v1.0.1 with: args: ". --check" +# test \ No newline at end of file From 75ce5db0cfd8d5219e13eb6ee47d51644397c44d Mon Sep 17 00:00:00 2001 From: sshinohs Date: Fri, 27 Jan 2023 13:47:36 +0900 Subject: [PATCH 02/17] test: black on --- .github/workflows/black.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index 5a17f1a..47fd60e 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -3,12 +3,12 @@ name: PyLinter-Black # Controls when the workflow will run -on: +on: [push, pull_request] # Triggers the workflow on push or pull request events but only for the main branch - push: - branches: [main, DEV] - pull_request: - branches: [main, DEV] + # push: + # branches: [main, DEV] + # pull_request: + # branches: [main, DEV] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: From 401499a0ebea1b7a0bd21abd60cd2b01dd7ff599 Mon Sep 17 00:00:00 2001 From: sshinohs Date: Fri, 27 Jan 2023 14:12:20 +0900 Subject: [PATCH 03/17] fix: black formatter github action --- .github/workflows/black.yml | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index 47fd60e..98b2a66 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -1,34 +1,10 @@ -# This is a basic workflow to help you get started with Actions +name: Lint -name: PyLinter-Black - -# Controls when the workflow will run on: [push, pull_request] - # Triggers the workflow on push or pull request events but only for the main branch - # push: - # branches: [main, DEV] - # pull_request: - # branches: [main, DEV] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on + lint: runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v3 - - - name: Black Code Formatter - # You may pin to the exact commit or the version. - # uses: lgeiger/black-action@4379f39aa4b6a3bb1cceb46a7665b9c26647d82d - uses: lgeiger/black-action@v1.0.1 - with: - args: ". --check" -# test \ No newline at end of file + - uses: actions/checkout@v2 + - uses: psf/black@stable \ No newline at end of file From a76a16b26ddc41ce79d6bab64041e03c131f2d54 Mon Sep 17 00:00:00 2001 From: sshinohs Date: Fri, 27 Jan 2023 14:18:08 +0900 Subject: [PATCH 04/17] fix: py file formatting --- .../PaintTransformer/inference_only_final.py | 61 ++++++++++++------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/backend/PaintTransformer/inference_only_final.py b/backend/PaintTransformer/inference_only_final.py index 58d4d9d..2f95570 100644 --- a/backend/PaintTransformer/inference_only_final.py +++ b/backend/PaintTransformer/inference_only_final.py @@ -12,12 +12,14 @@ idx = 0 + def save_img(img, output_path): result = Image.fromarray( (img.data.cpu().numpy().transpose((1, 2, 0)) * 255).astype(np.uint8) ) result.save(output_path) + def tensor_to_pil_image(image_tensor): pil_image = Image.fromarray( (image_tensor.data.cpu().numpy().transpose((1, 2, 0)) * 255).astype(np.uint8) @@ -562,21 +564,26 @@ def partial_render(this_canvas, patch_coord_y, patch_coord_x): return cur_canvas -def read_img(img, img_type='RGB', l=None): +def read_img(img, img_type="RGB", l=None): img = img.convert(img_type) if l is not None: original_w, original_h = img.size if original_w > original_h: - img = img.resize((l, int(l/original_w*original_h)), resample=Image.NEAREST) + img = img.resize( + (l, int(l / original_w * original_h)), resample=Image.NEAREST + ) else: - img = img.resize((int(l/original_h*original_w), l), resample=Image.NEAREST) + img = img.resize( + (int(l / original_h * original_w), l), resample=Image.NEAREST + ) img = np.array(img) if img.ndim == 2: img = np.expand_dims(img, axis=-1) img = img.transpose((2, 0, 1)) - img = torch.from_numpy(img).unsqueeze(0).float() / 255. + img = torch.from_numpy(img).unsqueeze(0).float() / 255.0 return img + def read_img_file(img_path, img_type="RGB", h=None, w=None): img = Image.open(img_path).convert(img_type) if h is not None and w is not None: @@ -627,9 +634,10 @@ def crop(img, h, w): def init(stroke_num: int, model_path: str): device = torch.device("cuda" if torch.cuda.is_available() else "cpu") model = prepare_infer_model(model_path, stroke_num, device) - meta_brushes = make_meta_brushes(device, mode="small") + meta_brushes = make_meta_brushes(device, mode="small") return model, meta_brushes, device + def inference( model, device, @@ -637,17 +645,17 @@ def inference( image, stroke_num: int, patch_size: int, - K: int=None, - resize_l: int=None, - serial: bool=False, + K: int = None, + resize_l: int = None, + serial: bool = False, ): print(image) with torch.no_grad(): - frame_dir ='/output' + frame_dir = "/output" frame_list = [] original_img = read_img(image, "RGB", resize_l).to(device) original_h, original_w = original_img.shape[-2:] - if K==None: + if K == None: K = max(math.ceil(math.log2(max(original_h, original_w) / patch_size)), 0) original_img_pad_size = patch_size * (2**K) original_img_pad = pad( @@ -705,7 +713,7 @@ def inference( decision=decision, meta_brushes=meta_brushes, cur_canvas=final_result, - frame_dir='/output', + frame_dir="/output", has_border=False, original_h=original_h, original_w=original_w, @@ -823,8 +831,12 @@ def make_meta_brushes(device: torch, mode: str = "large"): Returns: torch: meta_brushes """ - brush_L_vertical = read_img_file(f"PaintTransformer/brush/brush_{mode}_vertical.png", "L") - brush_L_horizontal = read_img_file(f"PaintTransformer/brush/brush_{mode}_horizontal.png", "L") + brush_L_vertical = read_img_file( + f"PaintTransformer/brush/brush_{mode}_vertical.png", "L" + ) + brush_L_horizontal = read_img_file( + f"PaintTransformer/brush/brush_{mode}_horizontal.png", "L" + ) return torch.cat([brush_L_vertical, brush_L_horizontal], dim=0).to(device) @@ -868,19 +880,26 @@ def make_path(input_path, output_dir): parser.add_argument("--input", dest="input", type=str, default="iu") args = parser.parse_args() + output_dir_name = ( + os.path.splitext(args.input)[0] + + "_resize_" + + "{:04d}".format(args.resize_l) + + "_K_" + + "{:01d}".format(args.K) + ) - output_dir_name = os.path.splitext(args.input)[0] + '_resize_' + '{:04d}'.format(args.resize_l) + '_K_' + '{:01d}'.format(args.K) - - output_dir_root = os.path.join('output', output_dir_name) + output_dir_root = os.path.join("output", output_dir_name) - input_path = os.path.join('input', args.input) + input_path = os.path.join("input", args.input) resize_l = args.resize_l K = args.K stroke_num = 8 patch_size = 32 - model, meta_brushes, device = init(stroke_num, model_path="PaintTransformer/model.pth") + model, meta_brushes, device = init( + stroke_num, model_path="PaintTransformer/model.pth" + ) inference( model, @@ -889,7 +908,7 @@ def make_path(input_path, output_dir): stroke_num=stroke_num, patch_size=32, K=K, - need_animation=True, # whether need intermediate results for animation. - resize_l=resize_l, # resize original input to this size. (max(w, h) = resize_l) - serial=True, # if need animation, serial must be True. + need_animation=True, # whether need intermediate results for animation. + resize_l=resize_l, # resize original input to this size. (max(w, h) = resize_l) + serial=True, # if need animation, serial must be True. ) From 6d54d44f1da78bb3e7edff373e6c1c5920e3b423 Mon Sep 17 00:00:00 2001 From: sshinohs Date: Fri, 27 Jan 2023 14:39:14 +0900 Subject: [PATCH 05/17] =?UTF-8?q?feat:=20pre-commit=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 14 ++++++++++++++ README.md | Bin 58 -> 420 bytes database/docker-compose.yaml | 2 +- vue-project/src/components/ExampleView.vue | 4 ++-- vue-project/src/views/BackUp.vue | 8 ++++---- vue-project/src/views/GameView.vue | 8 ++++---- vue-project/src/views/SelectView.vue | 4 ++-- vue-project/src/views/TransformView.vue | 2 +- 8 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..1525e31 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,14 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: check-yaml + - id: check-json +- repo: https://github.com/psf/black + rev: stable + hooks: + - id: black + language_version: python3.9 \ No newline at end of file diff --git a/README.md b/README.md index e7f174bf4322022acdd4ef148dc2955c5bb9844b..9a9de0b50a0c7317b99cc03ddb2f73820ae6ff0a 100644 GIT binary patch literal 420 zcmah_I|{-;5PgDGPBEa3ML-ceOG=|gj3y?S=p8(ON3am=Y*QE^VkI`Yfu(0q-);yB zL1b8%H@ok%^LjQQ7{kRJHawUJu|R++91IZ?d+b&`9=b$B_9ois!C*C5q8X093*fU{ z@(jNGAVK|d%S6vc)KdL`iZ&-R?H|z9CyrSTdqM58J6rkVizUE5J9JW^`ZiCGg}+Lm z-U?dDCMjpXatWHLbv4k}HK1dJ3H3sz4ymN}5HW+=g-5KmQTB9 ObXzikaGN$$6`VIaSy*`h delta 5 McmZ3&Y&F3O00m6}tN;K2 diff --git a/database/docker-compose.yaml b/database/docker-compose.yaml index 4eef52d..96334ed 100644 --- a/database/docker-compose.yaml +++ b/database/docker-compose.yaml @@ -12,7 +12,7 @@ services: POSTGRES_DB: mydatabase volumes: - "./init/:/docker-entrypoint-initdb.d/" - + # data-info-to-db: # build: # context: . diff --git a/vue-project/src/components/ExampleView.vue b/vue-project/src/components/ExampleView.vue index 18f203e..f049b67 100644 --- a/vue-project/src/components/ExampleView.vue +++ b/vue-project/src/components/ExampleView.vue @@ -1,7 +1,7 @@ diff --git a/vue-project/src/views/BackUp.vue b/vue-project/src/views/BackUp.vue index 4f29f58..b6ba9fe 100644 --- a/vue-project/src/views/BackUp.vue +++ b/vue-project/src/views/BackUp.vue @@ -87,14 +87,14 @@ game_status: 시작 전 0 각 문제 마다 +1(총 9) -> 게임이 끝날 때 10 this.paintImg=response['paint_img'] this.answer=response['answer'] this.result=response['result'] - + this.$store.commit('setOrigin',response['origin_img']) this.$store.commit('setPaint',response['paint_img']) this.$store.commit('setAnswer',response['answer']) this.$store.commit('setResult',response['result']) - + }, - + enter(){ if (this.text===this.answer[this.game_status-1]){ this.text='' @@ -110,7 +110,7 @@ game_status: 시작 전 0 각 문제 마다 +1(총 9) -> 게임이 끝날 때 10 this.game_status+=1 // this.getGame() }, - + } } diff --git a/vue-project/src/views/GameView.vue b/vue-project/src/views/GameView.vue index c111822..0ac333f 100644 --- a/vue-project/src/views/GameView.vue +++ b/vue-project/src/views/GameView.vue @@ -100,14 +100,14 @@ game_status: 시작 전 0 각 문제 마다 +1(총 9) -> 게임이 끝날 때 10 this.paintImg=response['paint_img'] this.answer=response['answer'] this.result=response['result'] - + this.$store.commit('setOrigin',response['origin_img']) this.$store.commit('setPaint',response['paint_img']) this.$store.commit('setAnswer',response['answer']) this.$store.commit('setResult',response['result']) - + }, - + enter(){ if (this.text===this.answer[this.game_status-1]){ this.text='' @@ -125,7 +125,7 @@ game_status: 시작 전 0 각 문제 마다 +1(총 9) -> 게임이 끝날 때 10 this.img_timer.value=100 this.total_timer.value=100 }, - + } } diff --git a/vue-project/src/views/SelectView.vue b/vue-project/src/views/SelectView.vue index c3141af..be2d3f2 100644 --- a/vue-project/src/views/SelectView.vue +++ b/vue-project/src/views/SelectView.vue @@ -28,7 +28,7 @@ Game start - + @@ -37,7 +37,7 @@