Table of Contents:
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
""" | |
Script for checking various elements of the runtime environment and print a large amount of diagnostic information. | |
This is meant to be used for debugging environments used with MONAI, but doesn't directly need MONAI itself. It will | |
print information about the environment including trying to get installed packages, test PyTorch with CUDA, and then | |
have MONAI print its debugging information if no errors encountered. If MONAI is not installed this script should still | |
work and produce useful information. | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
print("Version=",torch.__version__) | |
print("CUDA=",torch.cuda.is_available()) | |
for i in range(torch.cuda.device_count()): | |
props=torch.cuda.get_device_properties(i) | |
print(f" {props.name}, mem={int(props.total_memory/2**20)}MiB") | |
Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.
- Follow standard conventions.
- Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
- Boy scout rule. Leave the campground cleaner than you found it.
- Always find root cause. Always look for the root cause of a problem.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import json | |
import datetime | |
from typing import Union | |
# from https://gist.github.com/jannismain/e96666ca4f059c3e5bc28abb711b5c92 | |
class CompactJSONEncoder(json.JSONEncoder): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ignite.engine import Events, Engine | |
class Attachable: | |
""" | |
This class contains an internal dictionary `attach_map` associating events with the bound methods to be triggered | |
on those events. This dictionary can be populated by the contructor or by external clients after construction and | |
before `attach` is called. | |
""" | |
def __init__(self, attach_map): | |
self.attach_map = dict(attach_map) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import warnings | |
import threading | |
import numpy as np | |
from ignite.engine.engine import Engine, Events | |
def ensure_tuple(vals): | |
""" | |
Returns a tuple containing just `vals` if it is not a list or tuple, or `vals` converted to a tuple otherwise. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def matZero(n,m): | |
'''Return a list of lists with the given dimensions containing zeros.''' | |
return [[0]*m for i in range(n)] | |
def matIdent(n): | |
'''Return a list of lists defining the identity matrix of rank `n'.''' | |
mat=matZero(n,n) | |
for nn in range(n): | |
mat[nn][nn]=1.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import vtk | |
import os,sys,math | |
# read unstructured grid | |
r=vtk.vtkXMLUnstructuredGridReader() | |
r.SetFileName(sys.argv[1]) # first command line argument after script name | |
r.Update() | |
orig=r.GetOutput() |
NewerOlder