Categories
Misc

Why loss values don’t make sense for Dice, Focal, IOU for boundary detection Unet in Keras?

I am using Keras for boundary/contour detection using a Unet. When I use binary cross-entropy as the loss, the losses decrease over time as expected the predicted boundaries look reasonable

However, I have tried custom losses for Dice, Focal, IOU, with varying LRs, and none of them are working well. I either get NaNs or non-decreasing/barely-decreasing values for the losses. This is regardless of what I use for the LR, whether it be .01 to 1e-6, or whether I vary the ALPHA and GAMMA and other parameters. This doesn’t make sense since for my images, most of the pixels are the background, and the pixels corresponding to boundaries are the minority. For imbalanced datasets, IOU, Dice, and Focal should work better than binary Cross-Entropy

The code I used for the losses are from https://www.kaggle.com/bigironsphere/loss-function-library-keras-pytorch#Jaccard/Intersection-over-Union-(IoU)-Loss

def DiceLoss(targets, inputs, smooth=1e-6): #flatten label and prediction tensors inputs = K.flatten(inputs) targets = K.flatten(targets) intersection = K.sum(K.dot(targets, inputs)) dice = (2*intersection + smooth) / (K.sum(targets) + K.sum(inputs) + smooth) return 1 - dice ALPHA = 0.8 GAMMA = 2 def FocalLoss(targets, inputs, alpha=ALPHA, gamma=GAMMA): inputs = K.flatten(inputs) targets = K.flatten(targets) BCE = K.binary_crossentropy(targets, inputs) BCE_EXP = K.exp(-BCE) focal_loss = K.mean(alpha * K.pow((1-BCE_EXP), gamma) * BCE) return focal_loss def IoULoss(targets, inputs, smooth=1e-6): #flatten label and prediction tensors inputs = K.flatten(inputs) targets = K.flatten(targets) intersection = K.sum(K.dot(targets, inputs)) total = K.sum(targets) + K.sum(inputs) union = total - intersection IoU = (intersection + smooth) / (union + smooth) return 1 - IoU 

Even if I try different code for the losses, such as the code below

smooth = 1. def dice_coef(y_true, y_pred): y_true_f = K.flatten(y_true) y_pred_f = K.flatten(y_pred) intersection = K.sum(y_true_f * y_pred_f) return (2. * intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth) def dice_coef_loss(y_true, y_pred): return -dice_coef(y_true, y_pred) 

the loss values still don’t improve. That is, it will show something like

loss: nan - dice_coef_loss: .9607 - val_loss: nan - val_dice_coef_loss: .9631 

and the values won’t change much for each epoch

can anyone help?

submitted by /u/74throwaway
[visit reddit] [comments]

Categories
Misc

Tensorflow Tutorials for Audio Processing? Preferably Seperating Different Types of Audio

I have a dataset that contains a lot of audio files that I want Tensorflow to differentiate from. (For example, this audio is a women counting numbers, this audio is just plain static)

I have no idea where to start and googling just gives me some specific datasets that are used to differentiate songs.

What is a good place to start for audio processing?

submitted by /u/TuckleBuck88
[visit reddit] [comments]

Categories
Misc

ImportError: cannot import name ‘model_lib_v2’ from ‘object_detection’ (C:UsersASUSAppDataRoamingPythonPython38site-packagesobject_detection__init__.py)

ImportError: cannot import name 'model_lib_v2' from 'object_detection' (C:UsersASUSAppDataRoamingPythonPython38site-packagesobject_detection__init__.py)

Object detection api import error

This was what i managed to do succesfully. Basicallly followed instructions from here Gilbert Tanner github.

git clone https://github.com/tensorflow/models.git

cd models/research

# Compile protos.

protoc object_detection/protos/*.proto –python_out=.

# Install TensorFlow Object Detection API.

i manually copied setup.py from packages/tf2 folder to object_detection/packages/tf2/setup.py

python -m pip install .

All these ran smoothly without warning messages.

I tested it with

python -c “import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000,1000])))”
and it works fine i got the printed output without any error.

python generate_tfrecord.py –csv_input=images/train_labels.csv –image_dir=images/train –output_path=train.record
works as well i got the train.record file.

However, when i tried to Training the model with

python model_main_tf2.py –pipeline_config_path=training/ssd_efficientdet_d0_512x512_coco17_tpu-8.config –model_dir=training –alsologtostderr

this came up.

https://preview.redd.it/aqkt00tzmki61.png?width=1167&format=png&auto=webp&s=3b2e296fc9b7282d9d604459a178a1e6fd7826b9

submitted by /u/slpypnda
[visit reddit] [comments]

Categories
Misc

layer doesn’t create weights when given input shape

In The Sequential model | TensorFlow Core section Specifying the input shape in advance it says:

Generally, all layers in Keras need to know the shape of their inputs in order to be able to create their weights. So when you create a layer like this, initially, it has no weights:

“`python layer = layers.Dense(3) print(layer.weights) # Empty

Output

[] “`

But if I specify the input_shape, why the output is still empty?

“`python layer = layers.Dense(2, input_shape=(4,))

print(layer.weights) # Still empty “`

submitted by /u/Ynjxsjmh
[visit reddit] [comments]

Categories
Misc

I taught a TensorFlow model to tell if one is not wearing a mask. It even gets angry when the mask is covering the chin and not the nose πŸ˜… Runs as a WebAssembly application entirely inside the browser. No server interaction / storage whatsoever.

I taught a TensorFlow model to tell if one is not wearing a mask. It even gets angry when the mask is covering the chin and not the nose πŸ˜… Runs as a WebAssembly application entirely inside the browser. No server interaction / storage whatsoever. submitted by /u/preslavrachev
[visit reddit] [comments]
Categories
Offsites

Introducing Model Search: An Open Source Platform for Finding Optimal ML Models

The success of a neural network (NN) often depends on how well it can generalize to various tasks. However, designing NNs that can generalize well is challenging because the research community’s understanding of how a neural network generalizes is currently somewhat limited: What does the appropriate neural network look like for a given problem? How deep should it be? Which types of layers should be used? Would LSTMs be enough or would Transformer layers be better? Or maybe a combination of the two? Would ensembling or distillation boost performance? These tricky questions are made even more challenging when considering machine learning (ML) domains where there may exist better intuition and deeper understanding than others.

In recent years, AutoML algorithms have emerged [e.g., 1, 2, 3] to help researchers find the right neural network automatically without the need for manual experimentation. Techniques like neural architecture search (NAS), use algorithms, like reinforcement learning (RL), evolutionary algorithms, and combinatorial search, to build a neural network out of a given search space. With the proper setup, these techniques have demonstrated they are capable of delivering results that are better than the manually designed counterparts. But more often than not, these algorithms are compute heavy, and need thousands of models to train before converging. Moreover, they explore search spaces that are domain specific and incorporate substantial prior human knowledge that does not transfer well across domains. As an example, in image classification, the traditional NAS searches for two good building blocks (convolutional and downsampling blocks), that it arranges following traditional conventions to create the full network.

To overcome these shortcomings and to extend access to AutoML solutions to the broader research community, we are excited to announce the open source release of Model Search, a platform that helps researchers develop the best ML models, efficiently and automatically. Instead of focusing on a specific domain, Model Search is domain agnostic, flexible and is capable of finding the appropriate architecture that best fits a given dataset and problem, while minimizing coding time, effort and compute resources. It is built on Tensorflow, and can run either on a single machine or in a distributed setting.

Overview
The Model Search system consists of multiple trainers, a search algorithm, a transfer learning algorithm and a database to store the various evaluated models. The system runs both training and evaluation experiments for various ML models (different architectures and training techniques) in an adaptive, yet asynchronous, fashion. While each trainer conducts experiments independently, all trainers share the knowledge gained from their experiments. At the beginning of every cycle, the search algorithm looks up all the completed trials and uses beam search to decide what to try next. It then invokes mutation over one of the best architectures found thus far and assigns the resulting model back to a trainer.

Model Search schematic illustrating the distributed search and ensembling. Each trainer runs independently to train and evaluate a given model. The results are shared with the search algorithm, which it stores. The search algorithm then invokes mutation over one of the best architectures and then sends the new model back to a trainer for the next iteration. S is the set of training and validation examples and A are all the candidates used during training and search.

The system builds a neural network model from a set of predefined blocks, each of which represents a known micro-architecture, like LSTM, ResNet or Transformer layers. By using blocks of pre-existing architectural components, Model Search is able to leverage existing best knowledge from NAS research across domains. This approach is also more efficient, because it explores structures, not their more fundamental and detailed components, therefore reducing the scale of the search space.

Neural network micro architecture blocks that work well, e.g., a ResNet Block.

Because the Model Search framework is built on Tensorflow, blocks can implement any function that takes a tensor as an input. For example, imagine that one wants to introduce a new search space built with a selection of micro architectures. The framework will take the newly defined blocks and incorporate them into the search process so that algorithms can build the best possible neural network from the components provided. The blocks provided can even be fully defined neural networks that are already known to work for the problem of interest. In that case, Model Search can be configured to simply act as a powerful ensembling machine.

The search algorithms implemented in Model Search are adaptive, greedy and incremental, which makes them converge faster than RL algorithms. They do however imitate the β€œexplore & exploit” nature of RL algorithms by separating the search for a good candidate (explore step), and boosting accuracy by ensembling good candidates that were discovered (exploit step). The main search algorithm adaptively modifies one of the top k performing experiments (where k can be specified by the user) after applying random changes to the architecture or the training technique (e.g., making the architecture deeper).

An example of an evolution of a network over many experiments. Each color represents a different type of architecture block. The final network is formed via mutations of high performing candidate networks, in this case adding depth.

To further improve efficiency and accuracy, transfer learning is enabled between various internal experiments. Model Search does this in two ways β€” via knowledge distillation or weight sharing. Knowledge distillation allows one to improve candidates’ accuracies by adding a loss term that matches the high performing models’ predictions in addition to the ground truth. Weight sharing, on the other hand, bootstraps some of the parameters (after applying mutation) in the network from previously trained candidates by copying suitable weights from previously trained models and randomly initializing the remaining ones. This enables faster training, which allows opportunities to discover more (and better) architectures.

Experimental Results
Model Search improves upon production models with minimal iterations. In a recent paper, we demonstrated the capabilities of Model Search in the speech domain by discovering a model for keyword spotting and language identification. Over fewer than 200 iterations, the resulting model slightly improved upon internal state-of-the-art production models designed by experts in accuracy using ~130K fewer trainable parameters (184K compared to 315K parameters).

Model accuracy given iteration in our system compared to the previous production model for keyword spotting, a similar graph can be found for language identification in the linked paper.

We also applied Model Search to find an architecture suitable for image classification on the heavily explored CIFAR-10 imaging dataset. Using a set known convolution blocks, including convolutions, resnet blocks (i.e., two convolutions and a skip connection), NAS-A cells, fully connected layers, etc., we observed that we were able to quickly reach a benchmark accuracy of 91.83 in 209 trials (i.e., exploring only 209 models). In comparison, previous top performers reached the same threshold accuracy in 5807 trials for the NasNet algorithm (RL), and 1160 for PNAS (RL + Progressive).

Conclusion
We hope the Model Search code will provide researchers with a flexible, domain-agnostic framework for ML model discovery. By building upon previous knowledge for a given domain, we believe that this framework is powerful enough to build models with the state-of-the-art performance on well studied problems when provided with a search space composed of standard building blocks.

Acknowledgements
Special thanks to all code contributors to the open sourcing and the paper: Eugen Ehotaj, Scotty Yak, Malaika Handa, James Preiss, Pai Zhu, Aleks Kracun, Prashant Sridhar, Niranjan Subrahmanya, Ignacio Lopez Moreno, Hyun Jin Park, and Patrick Violette.

Categories
Misc

Cartesian product of tensors with batch dimension in Tensorflow

Hi, i’m a tensorflow noob, I would appreciate it if you could help me with this. I have 3 tensors of shape (?,15) and I want to get the Cartesian product of all the possible combinations, my output should be of dimension (?,15,15,15,3). How can I do it ?

submitted by /u/holypapa96
[visit reddit] [comments]

Categories
Misc

New Training Opportunities Now Available Worldwide from NVIDIA Deep Learning Institute Certified Instructors

For the first time ever, the NVIDIA Deep Learning Institute is making its popular instructor-led workshops available to the general public. With the launch of public workshops this week, enrollment will be open to individual developers, data scientists, researchers and students. NVIDIA is increasing accessibility and the number of courses available to participants around the Read article >

The post New Training Opportunities Now Available Worldwide from NVIDIA Deep Learning Institute Certified Instructors appeared first on The Official NVIDIA Blog.

Categories
Misc

State of the art in GANs for Image Editing!

State of the art in GANs for Image Editing! submitted by /u/MLtinkerer
[visit reddit] [comments]
Categories
Misc

[Overview] MLOps: What It Is, Why it Matters, and How To Implement it

Both legacy companies and many tech companies doing commercial ML have pain points regarding:

  • Moving to the cloud,
  • Creating and managing ML pipelines,
  • Scaling,
  • Dealing with sensitive data at scale,
  • And about a million other problems.

At the same time, if we want to be serious and actually have models touch real-life business problems and real people, we have to deal with the essentials like:

  • acquiring & cleaning large amounts of data;
  • setting up tracking and versioning for experiments and model training runs;
  • setting up the deployment and monitoring pipelines for the models that do get to production.
  • and we need to find a way to scale our ML operations to the needs of the business and/or users of our ML models.

This article gives you broad overview on the topic:

What is MLOps

submitted by /u/kk_ai
[visit reddit] [comments]