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 simple_network(): | |
x = tf.placeholder(tf.float32, shape=[None, 784]) # Placeholder for input | |
y_ = tf.placeholder(tf.float32, shape=[None, 10]) # Placeholder for true labels (used in training) | |
hidden_neurons = 16 # Number of neurons in the hidden layer | |
# Hidden layer | |
w_1 = weights([784, hidden_neurons]) | |
b_1 = biases([hidden_neurons]) | |
h_1 = tf.nn.sigmoid(tf.matmul(x, w_1) + b_1) # Order of x and w_1 matters here purely syntactically |
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 numpy as np | |
import cv2 | |
def read_image(path): | |
"""Reads image as grayscale and normalises and flattens the array.""" | |
img = cv2.imread(path, cv2.IMREAD_GRAYSCALE) # Load as grayscale | |
img = img / 255 # Normalise values | |
return img.flatten() # Flatten to shape [784] |
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 cv2 | |
import operator | |
import numpy as np | |
from matplotlib import pyplot as plt | |
def plot_many_images(images, titles, rows=1, columns=2): | |
"""Plots each image in a given list as a grid structure. using Matplotlib.""" | |
for i, image in enumerate(images): | |
plt.subplot(rows, columns, i+1) |
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 display_grid(grid, coords=False): | |
""" | |
Displays a 9x9 soduku grid in a nicely formatted way. | |
Args: | |
grid (str|dict|list): A string representing a Sudoku grid. Valid characters are digits from 1-9 and empty squares are | |
specified by 0 or . only. Any other characters are ignored. A `ValueError` will be raised if the input does | |
not specify exactly 81 valid grid positions. | |
Can accept a dictionary where each key is the position on the board from A1 to I9. | |
Can accept a list of strings or integers with empty squares represented by 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
def display_points(in_img, points, radius=5, colour=(0, 0, 255)): | |
"""Draws circular points on an image.""" | |
img = in_img.copy() | |
# Dynamically change to a colour image if necessary | |
if len(colour) == 3: | |
if len(img.shape) == 2: | |
img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) | |
elif img.shape[2] == 1: | |
img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) |
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 display_grid(grid, coords=False): | |
""" | |
Displays a 9x9 soduku grid in a nicely formatted way. | |
Args: | |
grid (str|dict|list): A string representing a Sudoku grid. Valid characters are digits from 1-9 and empty squares are | |
specified by 0 or . only. Any other characters are ignored. A `ValueError` will be raised if the input does | |
not specify exactly 81 valid grid positions. | |
Can accept a dictionary where each key is the position on the board from A1 to I9. | |
Can accept a list of strings or integers with empty squares represented by 0. |