Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Convolutional Neural Networks/dummy/__pycache__/dataset.cpython-35.pyc
Views: 13377
��Y�% � @ sZ d d l Z d d l Z d d l m Z d d d � Z Gd d � d � Z d d � Z d S) � N)�cachec C s6 | d k r t j | � d } t j | d t �| S)a� Generate the One-Hot encoded class-labels from an array of integers. For example, if class_number=2 and num_classes=4 then the one-hot encoded label is the float array: [0. 0. 1. 0.] :param class_numbers: Array of integers with class-numbers. Assume the integers are from zero to num_classes-1 inclusive. :param num_classes: Number of classes. If None then use max(class_numbers)+1. :return: 2-dim array of shape: [len(class_numbers), num_classes] N� �dtype)�np�max�eye�float)� class_numbers�num_classes� r �/output/dataset.py�one_hot_encoded s r c @ sR e Z d Z d d d � Z d d � Z d d d � Z d d � Z d d � Z d S)�DataSetz.jpgc C sm t j j | � } | | _ t d d � | D� � | _ g | _ g | _ g | _ g | _ g | _ d | _ x� t j | � D]� } t j j | | � } t j j | � r} | j j | � | j | � } | j j | � | j } | g t | � } | j j | � | j t j j | d � � } | j j | � | g t | � } | j j | � | j d 7_ q} Wd S)a� Create a data-set consisting of the filenames in the given directory and sub-dirs that match the given filename-extensions. For example, the knifey-spoony data-set (see knifey.py) has the following dir-structure: knifey-spoony/forky/ knifey-spoony/knifey/ knifey-spoony/spoony/ knifey-spoony/forky/test/ knifey-spoony/knifey/test/ knifey-spoony/spoony/test/ This means there are 3 classes called: forky, knifey, and spoony. If we set in_dir = "knifey-spoony/" and create a new DataSet-object then it will scan through these directories and create a training-set and test-set for each of these classes. The training-set will contain a list of all the *.jpg filenames in the following directories: knifey-spoony/forky/ knifey-spoony/knifey/ knifey-spoony/spoony/ The test-set will contain a list of all the *.jpg filenames in the following directories: knifey-spoony/forky/test/ knifey-spoony/knifey/test/ knifey-spoony/spoony/test/ See the TensorFlow Tutorial #09 for a usage example. :param in_dir: Root-dir for the files in the data-set. This would be 'knifey-spoony/' in the example above. :param exts: String or tuple of strings with valid filename-extensions. Not case-sensitive. :return: Object instance. c s s | ] } | j � Vq d S)N)�lower)�.0�extr r r � <genexpr>b s z#DataSet.__init__.<locals>.<genexpr>r �testr N)�os�path�abspath�in_dir�tuple�exts�class_names� filenames�filenames_testr �class_numbers_testr �listdir�join�isdir�append�_get_filenames�extend�len) �selfr r �nameZcurrent_dirr Zclass_numberr r r r r �__init__6 s. & zDataSet.__init__c C s[ g } t j j | � rW x<