Loading …

Machine learning

    [P] MR-based CT Generation (DCCC) Tensorflow Project

    [P] MR-based CT Generation (DCCC) Tensorflow Project

    Github link: github.com/ChengBinJin/MRI-to-CT-DCNN-TensorFlow

    https://i.redd.it/8uaqou55imt21.png

    submitted by /u/Cheng-BinJin
    [link] [comments]

    Source link

    Click here to read more

    [P] Probabilistic Cityscapes scene generator

    [P] Probabilistic Cityscapes scene generator

    Hey all, I've been working on a custom generative model for a while and I just trained it on the Cityscapes dataset. I was pleased with what it learned to produce in just 5 hours of training on a single GPU (1080 Ti), and also I think the generation process itself looks pretty neat so I made a video of that too.

    Here's 25 non cherry picked results

    https://i.redd.it/1hr1c1cc1us21.png

    And here's a video showing the generation process (different run, different result)

    https://reddit.com/link/be8fe1/video/qgbpckog1us21/player

    As you might be able to tell, it's an autoregressive model. However, it's different from PixelCNN and co in the sense that it doesn't sample from top left to bottom right, but instead it samples at random positions. The benefit is that as you get more samples, the dependencies between pixels get more and more local and you can get away with sampling more than a single subpixel per inference step as long as they are sufficiently far apart. In this example, it takes 145 steps to sample 24576 subpixels (64x128x3) so that's only like 0.6% of the amount of steps you need with a PixelCNN. I know I'm not the first one with this idea but I'm surprised with how well it seems to works. There's some more details I'm going to keep to myself for now, but I'm curious to hear what you think of the result so far.

    I think I should be able to scale it up to at least double this resolution on my single GPU, but first I want to try it on some other datasets. In fact, first thing I'm going to try it on is on some raw audio data to see if the same principle of parallel sampling works in that domain too.

    submitted by /u/zarcomup
    [link] [comments]

    Source link

    Click here to read more

    [P] PyCM 2.0 released: A general benchmark based comparison of classification models

    [P] PyCM 2.0 released: A general benchmark based comparison of classification models

    PyCM version 2.0 released

    http://www.pycm.ir

    https://github.com/sepandhaghighi/pycm

    In version 2.0 a method for comparing several confusion matrices is introduced. This option is a combination of several overall and class-based benchmarks. Each of the benchmarks evaluates the performance of the classification algorithm from good to poor and give them a numeric score. The score of good performance is 1 and for the poor performance is 0.

    After that, two scores are calculated for each confusion matrices, overall and class based. The overall score is the average of the score of four overall benchmarks which are Landis & Koch, Fleiss, Altman, and Cicchetti. And with a same manner, the class based score is the average of the score of three class-based benchmarks which are Positive Likelihood Ratio Interpretation, Discriminant Power Interpretation, and AUC value Interpretation. It should be notice that if one of the benchmarks returns none for one of the classes, that benchmarks will be eliminate in total averaging. If user set weights for the classes, the averaging over the value of class-based benchmark scores will transform to a weighted average.

    If the user set the value of by_class boolean input True, the best confusion matrix is the one with the maximum class-based score. Otherwise, if a confusion matrix obtain the maximum of the both overall and class-based score, that will be the reported as the best confusion matrix but in any other cases the compare object doesn’t select best confusion matrix.

    https://i.redd.it/7eacdtt2jhs21.png

    Changelog :

    • G-Mean (GM) added #178
    • Index of balanced accuracy (IBA) added #176
    • Optimized precision (OP) added #152
    • Pearson's C (C) added #180
    • Compare class added #111
    • Parameters recommendation warning added #174
    • ConfusionMatrix equal method added #181
    • Document modified #173
    • stat_print function bug fixed
    • table_print function bug fixed
    • Beta parameter renamed to beta (F_calc function & F_beta method)
    • Parameters recommendation for imbalance dataset modified
    • normalize parameter added to save_html method #183
    • pycm_func.py splitted into pycm_class_func.py and pycm_overall_func.py
    • vector_filter, vector_check, class_check and matrix_check functions moved to pycm_util.py
    • RACC_calc and RACCU_calc functions exception handler modified #187
    • Docstrings modified

    submitted by /u/sepandhaghighi
    [link] [comments]

    Source link

    Click here to read more

    [D]My Machine Learning Journal #10: First time doing reinforcement learning and beating atari breakout with it

    [D]My Machine Learning Journal #10: First time doing reinforcement learning and beating atari breakout with it

    I have been inconsistent with my journal, but I am back and fresher than ever.

    Vlog version as usual:

    https://youtu.be/dcnGI6x-yk0

    Today (and yesterday) I did & learned:

    RL seems to have a lot of exploration going on vs some other ML tasks. One popular application it has is definitely beating videogames. The Mario AI was a viral hit in 2015. I decided to build a RL model that can beat atari breakout. This was soon classified as impossible given my current coding skills, so I chose to implement a medium article first that beat atari breakout. This article was great at linking the original Atari breakout RL paper with the code, but the full code was not posted, so I was stuck. Luckily, a user named boyuanf hit us up with the tensorflow implementation of the article on medium, here's the forked version of it.

    I downloaded the trained weights and model, and I ran it after installing openAI gym in conda with pip. Unfortunately, atari-py seems incompatible with windows 10, so I had to go through a very annoying process to finally come through with this easy line of code to solve the problem:

    pip install --no-index -f https://github.com/Kojoley/atari-py/releases atari_py 

    Yea it is just one of those problems man.

    Anyways, I then was able to run gym and see the beautiful pre-trained model doing work, it got to a pretty good high score, I think 57 or something.

    It is actually after I implemented the project that I come back to reading the papers, this works for me. I usually try to guess what the original algorithm does by doing a project first. For me, doing a project first then reading the paper also gives that revelation of: "oh, the reason that I have this line in the code is because of that sentence in the paper".

    The paper and this medium article helped my understanding a lot. This pseudocode in the paper opened the doors for me:

    https://i.redd.it/6bpl6f203yr21.png

    I'm going to try to explain this pseudocode with even English-er language. We will input the current frame and a few previous frames to our RL model. The RL model will interpret these inputs as the state, and it will either choose the action based on the Q-table or choose a random action. We can imagine that as the model gets more advanced, we will choose less random actions to let the model learn, but in the early stages, when the model has no idea what to do, we probably want to let it explore randomly, we will use a decreasing epsilon value to model this. The emulator will receive the action chosen by the RL model, run that action, then display the new image and return the reward. The Q-table will be updated based on this reward. The Q-table is just a table that has states mapping to potential actions. When the model is complex and epsilon is low, the RL model chooses actions based on the Q-table, a higher value (which means high rewards) in the state mapping to action will probably mean the model is choosing that.

    That;s it for this one, I learned a lot since it was my first time exploring RL! Exciting, can't wait to do more.

    submitted by /u/RedditAcy
    [link] [comments]

    Source link

    Click here to read more

    [P] CppRl: A C++ reinforcement learning library using the new PyTorch C++ frontend

    [P] CppRl: A C++ reinforcement learning library using the new PyTorch C++ frontend

    I'm really excited to show you guys what I've been working on lately: https://github.com/Omegastick/pytorch-cpp-rl

    It is very heavily based on Ikostrikov's wonderful pytorch-a2c-ppo-acktr-gail. You could even consider this a port. The API and underlying algorithms are almost identical (with the necessary changes involved in the move to C++).

    It also contains a reimplementation simple OpenAI Gym server that communicates via ZeroMQ to test the framework on Gym environments.

    CppRl aims to be an extensible, reasonably optimized, production-ready framework for using reinforcement learning in projects where Python isn't viable. It should be ready to use in desktop applications on user's computers with minimal setup required on the user's side.

    Motivation

    At the time of writing, there are no general-use reinforcement learning frameworks for C++. I needed one for a personal project, and the PyTorch C++ frontend had recently been released, so I figured I should make one.

    Features

    • Implemented algorithms:
      • A2C
      • PPO
    • Recurrent policies (GRU based)
    • Cross-platform compatibility (tested on Windows 10, Ubuntu 16.04, and Ubuntu 18.04)
    • Solid test coverage
    • Decently optimized (always open to pull requests improving optimization though)

    Sample

    Processing gif r1w6ksghemr21...

    If you want to help with the project, please submit a PR!

    submitted by /u/Flag_Red
    [link] [comments]

    Source link

    Click here to read more

    How to Load Large Datasets From Directories for Deep Learning with Keras

    There are conventions for storing and structuring your image dataset on disk in order to make it fast and efficient to load and when training and evaluating deep learning models.

    Once structured, you can use tools like the ImageDataGenerator class in the Keras deep learning library to automatically load your train, test, and validation datasets. In addition, the generator will progressively load the images in your dataset, allowing you to work with both small and very large datasets containing thousands or millions of images that may not fit into system memory.

    In this tutorial, you will discover how to structure an image dataset and how to load it progressively when fitting and evaluating a deep learning model.

    After completing this tutorial, you will know:

    • How to organize train, test, and validation image datasets into a consistent directory structure.
    • How to use the ImageDataGenerator class to progressively load the images for a given dataset.
    • How to use a prepared data generator to train, evaluate, and make predictions with a deep learning model.

    Let’s get started.

    Tutorial Overview

    This tutorial is divided into three parts; they are:

    1. Dataset Directory Structure
    2. Example Dataset Structure
    3. How to Progressively Load Images

    Dataset Directory Structure

    There is a standard way to lay out your image data for modeling.

    After you have collected your images, you must sort them first by dataset, such as train, test, and validation, and second by their class.

    For example, imagine an image classification problem where we wish to classify photos of cars based on their color, e.g. red cars, blue cars, etc.

    First, we have a data/ directory where we will store all of the image data.

    Next, we will have a data/train/ directory for the training dataset and a data/test/ for the holdout test dataset. We may also have a data/validation/ for a validation dataset during training.

    So far, we have:

    data/
    data/train/
    data/test/
    data/validation/

    Under each of the dataset directories, we will have subdirectories, one for each class where the actual image files will be placed.

    For example, if we have a binary classification task for classifying photos of cars as either a red car or a blue car, we would have two classes, ‘red‘ and ‘blue‘, and therefore two class directories under each dataset directory.

    For example:

    data/
    data/train/
    data/train/red/
    data/train/blue/
    data/test/
    data/test/red/
    data/test/blue/
    data/validation/
    data/validation/red/
    data/validation/blue/

    Images of red cars would then be placed in the appropriate class directory.

    For example:

    data/train/red/car01.jpg
    data/train/red/car02.jpg
    data/train/red/car03.jpg
    ...
    data/train/blue/car01.jpg
    data/train/blue/car02.jpg
    data/train/blue/car03.jpg
    ...

    Remember, we are not placing the same files under the red/ and blue/ directories; instead, there are different photos of red cars and blue cars respectively.

    Also recall that we require different photos in the train, test, and validation datasets.

    The filenames used for the actual images often do not matter as we will load all images with given file extensions.

    A good naming convention, if you have the ability to rename files consistently, is to use some name followed by a number with zero padding, e.g. image0001.jpg if you have thousands of images for a class.

    Want Results with Deep Learning for Computer Vision?

    Take my free 7-day email crash course now (with sample code).

    Click to sign-up and also get a free PDF Ebook version of the course.

    Download Your FREE Mini-Coursehttps://machinelearningmastery.lpages.co/leadbox-1553357564.js

    Example Dataset Structure

    We can make the image dataset structure concrete with an example.

    Imagine we are classifying photographs of cars, as we discussed in the previous section. Specifically, a binary classification problem with red cars and blue cars.

    We must create the directory structure outlined in the previous section, specifically:

    data/
    data/train/
    data/train/red/
    data/train/blue/
    data/test/
    data/test/red/
    data/test/blue/
    data/validation/
    data/validation/red/
    data/validation/blue/

    Let’s actually create these directories.

    We can also put some photos in the directories.

    You can use the creative commons image search to find some images with a permissive license that you can download and use for this example.

    I will use two images:

    • Red Car, by Dennis Jarvis.
    • Blue Car, by Bill Smith.
    Red Car, by Dennis Jarvis

    Red Car, by Dennis Jarvis

    Blue Car, by Bill Smith

    Blue Car, by Bill Smith

    Download the photos to your current working directory and save the photo of the red car as ‘red_car_01.jpg‘ and the photo of the blue car as ‘blue_car_01.jpg‘.

    We must have different photos for each of the train, test, and validation datasets.

    In the interest of keeping this tutorial focused, we will re-use the same image files in each of the three datasets but pretend they are different photographs.

    Place copies of the ‘red_car_01.jpg‘ file in data/train/red/, data/test/red/, and data/validation/red/ directories.

    Now place copies of the ‘blue_car_01.jpg‘ file in data/train/blue/, data/test/blue/, and data/validation/blue/ directories.

    We now have a very basic dataset layout that looks like the following (output from the tree command):

    data
    ├── test
    │   ├── blue
    │   │   └── blue_car_01.jpg
    │   └── red
    │       └── red_car_01.jpg
    ├── train
    │   ├── blue
    │   │   └── blue_car_01.jpg
    │   └── red
    │       └── red_car_01.jpg
    └── validation
        ├── blue
        │   └── blue_car_01.jpg
        └── red
            └── red_car_01.jpg

    Below is a screenshot of the directory structure, taken from the Finder window on macOS.

    Screenshot of Image Dataset Directory and File Structure

    Screenshot of Image Dataset Directory and File Structure

    Now that we have a basic directory structure, let’s practice loading image data from file for use with modeling.

    How to Progressively Load Images

    It is possible to write code to manually load image data and return data ready for modeling.

    This would include walking the directory structure for a dataset, loading image data, and returning the input (pixel arrays) and output (class integer).

    Thankfully, we don’t need to write this code. Instead, we can use the ImageDataGenerator class provided by Keras.

    The main benefit of using this class to load the data is that images are loaded for a single dataset in batches, meaning that it can be used for loading both small datasets as well as very large image datasets with thousands or millions of images.

    Instead of loading all images into memory, it will load just enough images into memory for the current and perhaps the next few mini-batches when training and evaluating a deep learning model. I refer to this as progressive loading, as the dataset is progressively loaded from file, retrieving just enough data for what is needed immediately.

    Two additional benefits of the using the ImageDataGenerator class is that it can also automatically scale pixel values of images and it can automatically generate augmented versions of images. We will leave these topics for discussion in another tutorial and instead focus on how to use the ImageDataGenerator class to load image data from file.

    The pattern for using the ImageDataGenerator class is used as follows:

    1. Construct and configure an instance of the ImageDataGenerator class.
    2. Retrieve an iterator by calling the flow_from_directory() function.
    3. Use the iterator in the training or evaluation of a model.

    Let’s take a closer look at each step.

    The constructor for the ImageDataGenerator contains many arguments to specify how to manipulate the image data after it is loaded, including pixel scaling and data augmentation. We do not need any of these features at this stage, so configuring the ImageDataGenerator is easy.

    ...
    # create a data generator
    datagen = ImageDataGenerator()

    Next, an iterator is required to progressively load images for a single dataset.

    This requires calling the flow_from_directory() function and specifying the dataset directory, such as the train, test, or validation directory.

    The function also allows you to configure more details related to the loading of images. Of note is the ‘target_size‘ argument that allows you to load all images to a specific size, which is often required when modeling. The function defaults to square images with the size (256, 256).

    The function also allows you to specify the type of classification task via the ‘class_mode‘ argument, specifically whether it is ‘binary‘ or a multi-class classification ‘categorical‘.

    The default ‘batch_size‘ is 32, which means that 32 randomly selected images from across the classes in the dataset will be returned in each batch when training. Larger or smaller batches may be desired. You may also want to return batches in a deterministic order when evaluating a model, which you can do by setting ‘shuffle‘ to ‘False.’

    There are many other options, and I encourage you to review the API documentation.

    We can use the same ImageDataGenerator to prepare separate iterators for separate dataset directories. This is useful if we would like the same pixel scaling applied to multiple datasets (e.g. trian, test, etc.).

    ...
    # load and iterate training dataset
    train_it = datagen.flow_from_directory('data/train/', class_mode='binary', batch_size=64)
    # load and iterate validation dataset
    val_it = datagen.flow_from_directory('data/validation/', class_mode='binary', batch_size=64)
    # load and iterate test dataset
    test_it = datagen.flow_from_directory('data/test/', class_mode='binary', batch_size=64)

    Once the iterators have been prepared, we can use them when fitting and evaluating a deep learning model.

    For example, fitting a model with a data generator can be achieved by calling the fit_generator() function on the model and passing the training iterator (train_it). The validation iterator (val_it) can be specified when calling this function via the ‘validation_data‘ argument.

    The ‘steps_per_epoch‘ argument must be specified for the training iterator in order to define how many batches of images defines a single epoch.

    For example, if you have 1,000 images in the training dataset (across all classes) and a batch size of 64, then the steps_per_epoch would be about 16, or 1000/64.

    Similarly, if a validation iterator is applied, then the ‘validation_steps‘ argument must also be specified to indicate the number of batches in the validation dataset defining one epoch.

    ...
    # define model
    model = ...
    # fit model
    model.fit_generator(train_it, steps_per_epoch=16, validation_data=val_it, validation_steps=8)

    Once the model is fit, it can be evaluated on a test dataset using the evaluate_generator() function and passing in the test iterator (test_it). The ‘steps‘ argument defines the number of batches of samples to step through when evaluating the model before stopping.

    ...
    # evaluate model
    loss = model.evaluate_generator(test_it, steps=24)

    Finally, if you want to use your fit model for making predictions on a very large dataset, you can create an iterator for that dataset as well (e.g. predict_it) and call the predict_generator() function on the model.

    ...
    # make a prediction
    yhat = model.predict_generator(predict_it, steps=24)

    Let’s use our small dataset defined in the previous section to demonstrate how to define an ImageDataGenerator instance and prepare the dataset iterators.

    A complete example is listed below.

    # example of progressively loading images from file
    from keras.preprocessing.image import ImageDataGenerator
    # create generator
    datagen = ImageDataGenerator()
    # prepare an iterators for each dataset
    train_it = datagen.flow_from_directory('data/train/', class_mode='binary')
    val_it = datagen.flow_from_directory('data/validation/', class_mode='binary')
    test_it = datagen.flow_from_directory('data/test/', class_mode='binary')
    # confirm the iterator works
    batchX, batchy = train_it.next()
    print('Batch shape=%s, min=%.3f, max=%.3f' % (batchX.shape, batchX.min(), batchX.max()))

    Running the example first creates an instance of the ImageDataGenerator with all default configuration.

    Next, three iterators are created, one for each of the train, validation, and test binary classification datasets. As each iterator is created, we can see debug messages reporting the number of images and classes discovered and prepared.

    Finally, we test out the train iterator that would be used to fit a model. The first batch of images is retrieved and we can confirm that the batch contains two images, as only two images were available. We can also confirm that the images were loaded and forced to the square dimensions of 256 rows and 256 columns of pixels and the pixel data was not scaled and remains in the range [0, 255].

    Found 2 images belonging to 2 classes.
    Found 2 images belonging to 2 classes.
    Found 2 images belonging to 2 classes.
    Batch shape=(2, 256, 256, 3), min=0.000, max=255.000

    Further Reading

    This section provides more resources on the topic if you are looking to go deeper.

    API

    • Image Preprocessing Keras API
    • Sequential Model API

    Articles

    • Building powerful image classification models using very little data, Keras Blog.

    Summary

    In this tutorial, you discovered how to structure an image dataset and how to load it progressively when fitting and evaluating a deep learning model.

    Specifically, you learned:

    • How to organize train, test, and validation image datasets into a consistent directory structure.
    • How to use the ImageDataGenerator class to progressively load the images for a given dataset.
    • How to use a prepared data generator to train, evaluate, and make predictions with a deep learning model.

    Do you have any questions?
    Ask your questions in the comments below and I will do my best to answer.

    The post How to Load Large Datasets From Directories for Deep Learning with Keras appeared first on Machine Learning Mastery.

    Source link

    Click here to read more

    [P] PyTorch Implementation: Exploring Randomly Wired Neural Networks for Image Recognition

    [P] PyTorch Implementation: Exploring Randomly Wired Neural Networks for Image Recognition

    Recently, researchers at FAIR (including K. He) reported that randomly wired NNs perform better than or comparable to all existing hand-designed wiring(ResNet, ShuffleNet, etc.) and NAS-based results at ImageNet classification task: https://arxiv.org/abs/1904.01569

    These randomly wired NNs looked really strange and had caught my eye.

    So I decided to implement this in PyTorch and was able to reproduce some of their results.
    GitHub link: https://github.com/seungwonpark/RandWireNN

    Figure 4 from "Exploring Randomly Wired Neural Networks for Image Recognition" (1904.01569)

    Implementing this paper was really amusing! I never imagined that I would use graph-related algorithms(BFS, adjacency list) while doing ML.

    Note: Training is in progress - using an identical architecture with paper, I got 56.8% top-1 accuracy so far. It'll take some time to reach 74.7%, which was reported in the paper. I don't plan to use distributed SGD, but I hope to get comparable results using Adam/Adabound optimizer with learning rate decay.

    submitted by /u/seungwonpark
    [link] [comments]

    Source link

    Click here to read more

    [D] Can I say recommendation using Knowledge Graph Embedding generated from user-item graph is Collaborative filtering?

    [D] Can I say recommendation using Knowledge Graph Embedding generated from user-item graph is Collaborative filtering?

    I have generated a Knowledge Graph Embedding using TransR, and have used it in a Neural collaborative filtering framework[1] (with fixed embedding generated from TransR). Can I can this collaborative filtering?

    Embedding layer feed with TransR embeddings

    If I add user and item's other metadata can I call it Hybrid recommendation system?

    Is there similar to some published work?

    submitted by /u/gourxb
    [link] [comments]

    Source link

    Click here to read more

    [D] Neural Differential Equations

    [D] Neural Differential Equations

    Hi, I had a couple of questions about Neural ODEs. I am having trouble understanding some of the mechanics of the process.

    In a regular neural network (or a residual NN), I can understand that we move layer to layer and we get a new activation value in each layer until we finally get to the output. This makes sense to me because I understand that the output is going to be some vector of probabilities (if we were doing classification, for example).

    In a neural ODE, I don't quite get what's happening. Let's say I have a classification problem and for simplicity, let's say it's a binary output and there are like 5 inputs. Do each of those 5 inputs have their own ODE defining how their activations move throughout the layers?

    https://i.redd.it/vur6adwtgyp21.png

    Like, on this image, on the left, it SEEMS like to me that there is a vector of 7 inputs (1 observations, 7 variables for it) and it seems like to me that every layer we move, we get new activations and that there is some "optimal" path throughout the depth that defines EACH path. On the right side, it looks to me like again, there is 7 inputs. So, if there is 7 inputs, does that mean I need to solve 7 ODEs here?

    Or is it that not that there are 7 ODEs, but that there is 1 ODE and each of those inputs is like a different initial value and that there is one single ODE that defines the entire neural network? If it's this case, then can we solve this using any of the initial values? or does the ODE black-box solver take all 7 of the input values as initial values and solves them simultaneously? (I may be exposing some of my lack of ODE knowledge here)

    Okay, another question. In the graph on the left, assuming the 5th layer is my output layer, it feels obvious to me that I just push that set of activations through softmax or whatever and get my probabilities. However, on the right hand side, I have no idea what my "output" depth should be. Is this a trial and error thing? Like how do I get my final predictions here - confused haha

    Another question I have is regarding the way it's solved. Like at this point, it seems like ok I have some ODE solved that defines the model. So, now I want to update the weights. I put it through a loss function, get some difference - how do I do this update then? I am a bit confused about backprop in this system. I don't need the mathematical details but just the intuition would be nice.

    I would really really appreciate if someone could make this clear for me! I been reading up on this a lot and just having trouble clarifying these few things. Thank you so much

    submitted by /u/bthi
    [link] [comments]

    Source link

    Click here to read more