This file contains 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 dicom_generator(dicom_chunks): | |
i = 0 | |
while True: | |
_inp = dicom_chunks[i] | |
_img = read_dicom(_inp) | |
yield _img | |
i += 1 # Exploiting the stateful nature of generators |
This file contains 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 read_dicom(inp): | |
dicom = pydicom.dcmread(file_path) | |
image = dicom.pixel_array | |
if image.max() - image.min() > 0: | |
image = (image - image.min()) / (image.max() - image.min()) | |
if dicom.PhotometricInterpretation == 'MONOCHROME1': | |
image = 1 - image |
This file contains 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 random, pydicom, numpy as np, tensorflow as tf |
This file contains 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 f(): | |
'''Modified PEP 255 example''' | |
try: | |
yield 1 | |
try: | |
yield 2 | |
1/0 # zero division to trigger ZeroDivisionError | |
yield 3 # never get here | |
except ZeroDivisionError: | |
yield 4 |
This file contains 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
@tf.function | |
def run_named_tuple_graph(): | |
_ijk0 = (tf.constant(0), Pair(tf.constant(1), tf.constant(2))) | |
_ijk_fin = tf.while_loop(c, b, _ijk0) | |
return _ijk_fin | |
ijk_final = run_named_tuple_graph() | |
print(ijk_final[-1].j.numpy(), ijk_final[-1].k.numpy()) |
This file contains 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
Pair = collections.namedtuple('Pair', 'j, k') | |
ijk_0 = (tf.constant(0), Pair(tf.constant(1), tf.constant(2))) | |
c = lambda i, p: i < 10 | |
b = lambda i, p: (i + 1, Pair((p.j + p.k), (p.j - p.k))) | |
ijk_final = tf.while_loop(c, b, ijk_0) | |
print(ijk_final[-1].j.numpy(), ijk_final[-1].k.numpy()) | |
print(ijk_final[-1][0].numpy(), ijk_final[-1][1].numpy()) |
This file contains 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
for i in range(10): | |
p = Pair((p.j + p.k), (p.j - p.k)) |
This file contains 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
Pair = collections.namedtuple('Pair', 'j k') | |
p = Pair(1.0, 2.0) |
This file contains 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 collections, tensorflow as tf |
This file contains 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
!openssl verify -CAfile /root/ca/intermediate/certs/ca-chain.cert.pem \ | |
/root/ca/user/user.cert.pem |