コード例 #1
0
ファイル: gui.py プロジェクト: gelles-brandeis/tapqir
def cdCmd(path, DEFAULTS, layout):
    """
    Set working directory and load default parameters (main).
    """
    import sys
    from platform import uname

    IN_COLAB = "google.colab" in sys.modules
    IN_WSL2 = "microsoft-standard" in uname().release
    IN_LINUX = not IN_COLAB and not IN_WSL2

    out = layout["out"]
    path = get_path(path)
    with out:
        main(cd=path)
        logger.info("Loading configuration data ...")

    # Tabs
    tab = widgets.Tab()
    tab.children = [glimpseUI(out, DEFAULTS), fitUI(out, DEFAULTS)]
    if IN_LINUX:
        tensorboard = widgets.Output()
        tab.children = tab.children + (showUI(out, DEFAULTS), tensorboard)
    elif IN_WSL2:
        tensorboard = None
        tensorboard_info = widgets.Label(
            value=(
                'Run "tensorboard --logdir=<working directory>" in the terminal'
                ' and then open "localhost:6006" in the browser'
            )
        )
        tab.children = tab.children + (showUI(out, DEFAULTS), tensorboard_info)
    elif IN_COLAB:
        tensorboard = None
        tab.children = tab.children + (
            widgets.Label(value="Disabled in Colab"),
            widgets.Label(value="Disabled in Colab"),
        )
    tab.children = tab.children + (logUI(out),)
    tab.set_title(0, "Extract AOIs")
    tab.set_title(1, "Fit the data")
    tab.set_title(2, "View results")
    tab.set_title(3, "Tensorboard")
    tab.set_title(4, "View logs")

    if tensorboard is not None:
        with tensorboard:
            notebook.start(f"--logdir '{path}'")
            notebook.display(height=1000)

    # insert tabs into GUI
    wd = widgets.Label(value=f"Working directory: {path}")
    layout.remove_child("cd")
    layout.add_child("tab", tab, beginning=True)
    layout.add_child("wd", wd, beginning=True)

    with out:
        logger.info("Loading configuration data: Done")

    out.clear_output(wait=True)
コード例 #2
0
def setup_tensorboard(args):
    from tensorboard import notebook, manager
    import signal
    import shutil
    # Kill tensorboard
    for info in manager.get_all():
        data_source = manager.data_source_from_info(info)
        print(f"port {info.port}: {data_source} (pid {info.pid})")
        if data_source == "logdir {args.output_dir}":
            pid = info.pid
            logger.info(f"Killing tensorboard at pid: {pid}")
            os.kill(pid, signal.SIGKILL)
            break
    # Delete output directory
    if os.path.exists(args.output_dir):
        logger.info(f"Deleting {args.output_dir}")
        shutil.rmtree(args.output_dir)
    logger.info(f"Creating {args.output_dir}")
    os.makedirs(args.output_dir)
    # Start notebook
    notebook.start(f"--logdir {args.output_dir}")
    # Kill tensorboard
    for info in manager.get_all():
        data_source = manager.data_source_from_info(info)
        print(f"port {info.port}: {data_source} (pid {info.pid})")
        if data_source == "logdir {args.output_dir}":
            port = info.port
            print()
            notebook.display(port=port, height=1000)
            break
コード例 #3
0
    def forward(self, x):
        x = self.conv1(x)
        x = self.pool(x)
        x = self.conv2(x)
        x = self.pool(x)
        x = self.dropout(x)
        x = self.adaptive_pool(x)
        x = self.flatten(x)
        x = self.linear1(x)
        x = self.relu(x)
        x = self.linear2(x)
        y = self.sigmoid(x)
        return y


net = Net()
print(net)

writer = SummaryWriter('./data/tensorboard')
writer.add_graph(net,input_to_model = torch.rand(1,3,32,32))
writer.close()

from tensorboard import notebook
#查看启动的tensorboard程序
notebook.list()

#启动tensorboard程序
notebook.start("--logdir ./data/tensorboard")
#等价于在命令行中执行 tensorboard --logdir ./data/tensorboard
#可以在浏览器中打开 http://localhost:6006/ 查看
コード例 #4
0
model.summary()

import datetime
import os

stamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
logdir = os.path.join('data', 'autograph', stamp)

## 在 Python3 下建议使用 pathlib 修正各操作系统的路径
# from pathlib import Path
# stamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
# logdir = str(Path('./data/autograph/' + stamp))

tensorboard_callback = tf.keras.callbacks.TensorBoard(logdir, histogram_freq=1)

model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.001),
              loss=tf.keras.losses.binary_crossentropy,
              metrics=["accuracy"])

history = model.fit(ds_train,
                    epochs=10,
                    validation_data=ds_test,
                    callbacks=[tensorboard_callback],
                    workers=4)

from tensorboard import notebook
notebook.list()

#在tensorboard中查看模型
notebook.start("--logdir /home/kesci/input/data3483/data/keras_model")
コード例 #5
0
ファイル: main.py プロジェクト: divertingPan/postcard_cls
                        default=18,
                        type=int,
                        help="dataloader num_worker")
    parser.add_argument("--NETWORK",
                        default='senet',
                        type=str,
                        help="network structure",
                        choices=['resnet', 'senet', 'repvgg'])
    opt = parser.parse_args()
    print(json.dumps(vars(opt)))

    DEVICE = torch.device('cuda:1' if torch.cuda.is_available() else 'cpu')
    torch.backends.cudnn.benchmark = True
    log_dir = './log'
    timestamp = time.strftime('%Y-%m-%d-%H_%M_%S', time.localtime(time.time()))
    notebook.start("--logdir {}".format(log_dir))
    writer = SummaryWriter(os.path.join(log_dir, timestamp))

    df = pd.read_csv('./dataset/label.csv')
    weight_list = df['train_cls'].values
    weight_list = 1 / weight_list
    weight_list = torch.tensor(weight_list).float()

    train_transform = transforms.Compose([
        transforms.ToPILImage(),
        # transforms.Resize(256),
        transforms.RandomAffine(10, shear=0.1, fillcolor=(255, 255, 255)),
        transforms.ColorJitter(brightness=0.1,
                               contrast=0.1,
                               saturation=0.1,
                               hue=0.1),