{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "# Solutions\n", "## Problem 1\n", "Implement the Min-Max scaling function ($X'=a+{\\frac {\\left(X-X_{\\min }\\right)\\left(b-a\\right)}{X_{\\max }-X_{\\min }}}$) with the parameters:\n", "\n", "$X_{\\min }=0$\n", "\n", "$X_{\\max }=255$\n", "\n", "$a=0.1$\n", "\n", "$b=0.9$" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Problem 1 - Implement Min-Max scaling for grayscale image data\n", "def normalize_grayscale(image_data):\n", " \"\"\"\n", " Normalize the image data with Min-Max scaling to a range of [0.1, 0.9]\n", " :param image_data: The image data to be normalized\n", " :return: Normalized image data\n", " \"\"\"\n", " a = 0.1\n", " b = 0.9\n", " grayscale_min = 0\n", " grayscale_max = 255\n", " return a + ( ( (image_data - grayscale_min)*(b - a) )/( grayscale_max - grayscale_min ) )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem 2\n", "- Use [tf.placeholder()](https://www.tensorflow.org/api_docs/python/io_ops.html#placeholder) for `features` and `labels` since they are the inputs to the model.\n", "- Any math operations must have the same type on both sides of the operator. The weights are float32, so the `features` and `labels` must also be float32.\n", "- Use [tf.Variable()](https://www.tensorflow.org/api_docs/python/state_ops.html#Variable) to allow `weights` and `biases` to be modified.\n", "- The `weights` must be the dimensions of features by labels. The number of features is the size of the image, 28*28=784. The size of labels is 10.\n", "- The `biases` must be the dimensions of the labels, which is 10." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "features_count = 784\n", "labels_count = 10\n", "\n", "# Problem 2 - Set the features and labels tensors\n", "features = tf.placeholder(tf.float32)\n", "labels = tf.placeholder(tf.float32)\n", "\n", "# Problem 2 - Set the weights and biases tensors\n", "weights = tf.Variable(tf.truncated_normal((features_count, labels_count)))\n", "biases = tf.Variable(tf.zeros(labels_count))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 3\n", "Configuration 1\n", "* **Epochs:** 1\n", "* **Learning Rate:** 0.1\n", "\n", "Configuration 2\n", "* **Epochs:** 4 or 5\n", "* **Learning Rate:** 0.2" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.2" } }, "nbformat": 4, "nbformat_minor": 0 }