Skip to content

Commit

Permalink
feat: doc options auto update
Browse files Browse the repository at this point in the history
  • Loading branch information
pnsuau committed Mar 28, 2022
1 parent cb24c47 commit 1b08f92
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/github-actions-doc-options-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: GitHub Actions Demo
on:
push:
branches: [master]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- name: setup python
uses: actions/setup-python@v2
with:
python-version: 3.8 #install the python needed
- name : checkout
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Update submodules
run: git submodule update --init --recursive
- name : install req
run: pip install -r ./.github/workflows/requirements_github_actions.txt
- name : update
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name : run script
run: python ./scripts/generate_doc.py
- name : push
run : |
git config user.name github-actions-jg
git config user.email contact@jolibrain.com
git add .
git diff-index --quiet HEAD || (git commit -m "doc: options auto update" && git push)
9 changes: 9 additions & 0 deletions .github/workflows/requirements_github_actions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-f https://download.pytorch.org/whl/cu113/torch_stable.html
torch==1.10.1+cu113
numpy==1.19.5
Pillow==8.4.0
torchvision==0.11.2+cu113
timm==0.5.4
visdom==0.1.8.9
torchviz
imgaug
6 changes: 4 additions & 2 deletions models/modules/segformer/segformer_generator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
from mmseg.models import build_segmentor
from torch import nn
import mmcv

from models.modules.resnet_architecture.resnet_generator import ResnetDecoder
from models.modules.attn_network import BaseGenerator_attn
Expand All @@ -11,10 +9,12 @@
class Segformer(nn.Module):
def __init__(self,jg_dir,G_config_segformer,img_size,num_classes=10,final_conv=False):
super().__init__()
import mmcv
cfg = mmcv.Config.fromfile(os.path.join(jg_dir,G_config_segformer))
cfg.model.pretrained = None
cfg.model.train_cfg = None
cfg.model.decode_head.num_classes = num_classes
from mmseg.models import build_segmentor
self.net = build_segmentor(cfg.model, train_cfg=None, test_cfg=cfg.get('test_cfg'))

configure_encoder_decoder(self.net)
Expand Down Expand Up @@ -48,6 +48,7 @@ def __init__(self,jg_dir,G_config_segformer,img_size,nb_mask_attn,nb_mask_input,
self.use_final_conv = final_conv
self.tanh = nn.Tanh()

import mmcv
cfg = mmcv.Config.fromfile(os.path.join(jg_dir,G_config_segformer))
cfg.model.pretrained = None
cfg.model.train_cfg = None
Expand All @@ -58,6 +59,7 @@ def __init__(self,jg_dir,G_config_segformer,img_size,nb_mask_attn,nb_mask_input,
num_cls = 3*(self.nb_mask_attn-self.nb_mask_input)
cfg.model.decode_head.num_classes = num_cls
cfg.model.auxiliary_head.num_classes = self.nb_mask_attn
from mmseg.models import build_segmentor
self.segformer = build_segmentor(cfg.model, train_cfg=None, test_cfg=cfg.get('test_cfg'))
self.segformer.train()
self.softmax_ = nn.Softmax(dim=1)
Expand Down
6 changes: 3 additions & 3 deletions models/modules/segformer/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from mmseg.models.utils import nlc_to_nchw
from mmseg.ops import resize

def configure_compute_feat_mit(obj):
def compute_feat_mit(x, extract_layer_ids=[]):
outs = []
Expand All @@ -11,6 +8,7 @@ def compute_feat_mit(x, extract_layer_ids=[]):
for block in layer[1]:
x = block(x, hw_shape)
x = layer[2](x)
from mmseg.models.utils import nlc_to_nchw
x = nlc_to_nchw(x, hw_shape)
if i in obj.out_indices:
outs.append(x)
Expand Down Expand Up @@ -38,6 +36,7 @@ def decode_encoder_encoder(outs,use_resize=True):
map of the same size as input."""
out = obj._decode_head_forward_test(outs, img_metas=None)
if use_resize:
from mmseg.ops import resize
out = resize(
input=out,
size=obj.img_size,
Expand All @@ -53,6 +52,7 @@ def decode_2_encoder_encoder(outs,use_resize=True):
"""Encode images with backbone and decode into a semantic segmentation
map of the same size as input."""
out2 = obj._auxiliary_head_forward_test(outs, img_metas=None)
from mmseg.ops import resize
out2 = resize(
input=out2,
size=obj.img_size,
Expand Down
8 changes: 7 additions & 1 deletion scripts/generate_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from argparse import _HelpAction, _SubParsersAction, _StoreConstAction
import logging

sys.path.append('../')
jg_dir=os.path.join("/".join(os.path.abspath(__file__).split("/")[:-2]))
sys.path.append(jg_dir)

import options as opt

def main():
Expand Down Expand Up @@ -36,6 +38,10 @@ def main():

print(options_md)

path_sv = os.path.join(jg_dir,'docs','options.md')
with open(path_sv,'w+') as file:
file.writelines(options_md)

# ====

# inspired by https://github.com/alex-rudakov/sphinx-argparse/blob/master/sphinxarg/parser.py (v0.2.5)
Expand Down

0 comments on commit 1b08f92

Please sign in to comment.