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
!cat ./message.priv.enc | base64 -d | openssl rsautl -verify -pubin -inkey ./self_signed_cert.pub.key -in - > ./message.priv.dec |
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
!cat ./message.txt | openssl rsautl -sign -inkey ./self_signed_cert.key -in - -out - | base64 > ./message.priv.enc |
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 rsautl -inkey ./self_signed_cert.key -decrypt -in ./message.enc -out ./message.dec |
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 dgst -sha512 -binary ./message.enc | openssl base64 -A |
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 rsautl -pubin -inkey ./self_signed_cert.pub.key -encrypt -in ./message.txt -out ./message.enc |
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 x509 -pubkey -noout -in ./self_signed_cert.crt -out ./self_signed_cert.pub.key |
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 tflite_preds(X, tflite_model): | |
_interpreter = tf.lite.Interpreter(model_content=tflite_model) | |
_interpreter.allocate_tensors() | |
_input_details = _interpreter.get_input_details() | |
_output_details = _interpreter.get_output_details() | |
_interpreter.set_tensor(_input_details[0]['index'], tf.cast(X, dtype=tf.float32)) | |
del X; _interpreter.invoke() | |
_out_pred = _interpreter.get_tensor(_output_details[0]['index']) | |
return np.squeeze(np.asarray(_out_pred), axis=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
class TfLiteModel(): | |
def __init__(self, model): | |
self.model = model | |
def predict(self, X, **kwargs): | |
_tflite_model = dynamic_range_quantize_model(self.model) | |
_x = np.asarray(X); assert len(X.shape)>=2 | |
_tflite_out_preds = list(map(lambda i : tflite_preds(np.expand_dims(_x[i,:],axis=0), _tflite_model), range(_x.shape[0]) )) | |
return np.asarray(_tflite_out_preds) |
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 dynamic_range_quantize_model(model): | |
_converter = tf.lite.TFLiteConverter.from_keras_model(model) | |
del model | |
_converter.optimizations = [tf.lite.Optimize.DEFAULT] | |
_converter.target_spec.supported_ops = [ | |
tf.lite.OpsSet.TFLITE_BUILTINS, # enable TensorFlow Lite ops. | |
tf.lite.OpsSet.SELECT_TF_OPS # enable TensorFlow ops. | |
] | |
_tflite_model = _converter.convert() | |
del _converter |
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
class DicomGenerator(tf.keras.utils.Sequence): | |
def __init__(self, dicom_path, batch_size=1, dtype='float32', | |
shuffle=False, drop_remainder=False, | |
preserve_batch_size=False, **kwargs): | |
self.i = 0 | |
self.batch_size = batch_size | |
self.dtype = dtype | |
self.n = len(dicom_path) | |
self.dicom_path = dicom_path | |
self.drop_remainder = drop_remainder |
NewerOlder