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
| html += f""" | |
| <body> | |
| <!-- Page Content --> | |
| <div class="container"> | |
| <div class="row"> | |
| <div class="col-lg-12 text-left"> | |
| <h1 class="mt-5">{fullpath[-1]}</h1> | |
| <p class="lead"> |
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
| html = """ | |
| <h2>Functions</h2> | |
| <br> | |
| <ul> | |
| """ # initialise html object | |
| # iterate through and add function sections | |
| for name in funcs: | |
| html += f""" | |
| <li class="list-group-item" id="func_{name}"> |
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
| # if length of classes is not zero | |
| if len(classes) > 0: | |
| # add class section start | |
| html += """ | |
| <h2>Classes</h2> | |
| <div class="row"> | |
| <!-- Class Buttons --> | |
| <div class="col-4"> | |
| <div class="list-group" id="list-mod" role="tablist"> | |
| """ |
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
| <!-- Bootstrap core JavaScript --> | |
| <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> | |
| <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script> | |
| </body> | |
| </html> |
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 | |
| from email.mime.text import MIMEText | |
| from email.mime.image import MIMEImage | |
| from email.mime.application import MIMEApplication | |
| from email.mime.multipart import MIMEMultipart | |
| def message(subject="Python Notification", text="", img=None, attachment=None): | |
| # build message contents | |
| msg = MIMEMultipart() | |
| msg['Subject'] = subject # add in the subject |
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 smtplib | |
| import socket | |
| def send(msg, server='smtp-mail.outlook.com', port='587'): | |
| # contain following in try-except in case of momentary network errors | |
| try: | |
| # initialise connection to email server, the default is Outlook | |
| smtp = smtplib.SMTP(server, port) | |
| # this is the 'Extended Hello' command, essentially greeting our SMTP or ESMTP server | |
| smtp.ehlo() |
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 format_data(data, buffer, batchsize, colour=False): | |
| # if using grayscale, must make array 3-D with depth/z = 1 | |
| if not colour: | |
| data = [np.reshape(x, (x.shape[0], x.shape[1], 1)) for x in data] | |
| data = tf.data.Dataset.from_tensor_slices(data) # convert to TF dataset object | |
| # shuffle the data and place into batches | |
| data = data.shuffle(buffer).batch(batchsize, drop_remainder=True) |
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 downsample_rgb(array, downsample): | |
| # function to downsample RGB array dimensions without affecting colour dims | |
| r = skimage.measure.block_reduce(array[:, :, 0], (downsample, downsample), np.mean) | |
| g = skimage.measure.block_reduce(array[:, :, 1], (downsample, downsample), np.mean) | |
| b = skimage.measure.block_reduce(array[:, :, 2], (downsample, downsample), np.mean) | |
| return np.stack((r, g, b), axis=-1) # return each downsampled array stacked in | |
| def import_image(path, colour, downsample): | |
| # load the image | |
| image = Image.open(path) |
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
| # this should be placed outside the class, as it will be used by the discriminator too | |
| cross_entropy = tf.keras.losses.BinaryCrossentropy(from_logits=True) | |
| # the following are contained within the Generator class | |
| def optimiser(self, learning_rate): | |
| self.opt = tf.optimizers.Adam(learning_rate) | |
| def loss(self, fake_preds): | |
| # calculate the loss with binary cross-entropy | |
| fake_loss = cross_entropy(tf.ones_like(fake_preds), fake_preds) |