text:
What is the fastest way to train a CNN with billions of examples?
I have a CNN model that I need to train for a large scale genomics application. It is working well with a subset of my training data. I have scaled up to a subset of about 130 million examples and training time is very long, about 3 hours per epoch. I plan to scale up to the hundreds of billions of training examples and I anticipate training time to be not be feasible with my current design. I would appreciate feedback on how I can streamline the training or improve some aspect of my design that I may not be considering. Currently, I am training from a MongoDB. The training examples are not very large. Here is an example.
{
    'added': datetime.datetime(2019, 11, 1, 6, 13, 13, 340000),
    '_id': ObjectId('5dbbccf92464af872756022e'),
    'label': 0,
    'accession': 'GM_0001',
    'data': '34363,30450,9019,19152,8726,22128,59881,17670,15803,64454,64579,28103,52442,64951,29783,64574,652,19243,33498,14775,18803,4700,55446,53912,47645,41465,48257,16305,62071,12334,44698,24371,46515,8445,3000,61849,43228,18120,23587,11105,5453,42707,42739,46122,31285,40773,48162,16653,58783,2928,2836,21330,46947,6719,26992,8852,14520,46212,47362,43554,2147,39372,33885,59716,37384,14825,53387,58763,18065,34070,23278,15641,40237,47950,58811,40015,36880,29841,45351,14904,49660,48224,54638,50358,17202,10701,3564,4829,62655,5684,37207,49724,16369,6769,37827,38144,63885,5070,42882,48960,16178,35758,50554,54253,34556,2383,39431,30176,11482,24459,4472,53825,7764,44500,4869,50875,33037,56353,46848,30769,18729,46026,41409,2826,12092,17086',
    'name': 'Example_1'
}

The relevant data is the 'data' field which is a string of 126 integers where each integer is a value between 0 and about 65,000. The other fields are convenient, but not necessary except for the 'label' field. But even this I could insert into the front of the data field. I mention this because I don't think I necessarily need to train from a MongoDB database.
I am using Keras 2.3.0 with TensorFlow 2.0.0. Below is an example of my code. The workflow is 1) Load a text file containing the document ids of all training examples in the MongoDB collection. I do this so I can shuffle the examples before sending them to the model for training. 2) I load the examples in batches of 50,000 using my Custom_Generator class. This class pulls the documents from the MongoDB using the list of document ids. 3) The model is trained. I use 5 epochs. I currently have 5-fold cross-validation but I know this is not feasible on the full training set. For that I will do a single train-test split. I am currently performing this on a Google Cloud instance with 2 Tesla T4 GPUs. The database is on a bucket. With the cloud I have flexibility of hardware architectures. I would appreciate any insight. This is a rather large engineering challenge for me.
Additional background to the problem:
The objective is to classify organisms into broad classes quickly for downstream analysis. The pool of organisms I want to classify is very large (10s of thousands) and very diverse. I'm essentially reading the genomes of the organisms like a book. The genome (a series of "A", "T", "C", or "G") is processed in chunks through a hash function producing integer strings as shown above. Depending on the size of the organism genome, thousands to millions of these integer strings may be produced. So I have many thousands of organisms producing many thousands to millions of examples. To be successful, I feel like I need to capture the diversity of the genomes in the organism pool. To give an example, even though Ecoli and Salmonella are both bacteria, their genomes are quite distinct. I feel like I need to have them both represented in the training set to distinguish them from other organisms I would label as a different class. As far as reducing the dataset, I think I can get by with only training on a representative organism for a give species (since there are many unique genomes available for Ecoli, for example). This will help considerably, but I think the training data set will likely still be in the billions of examples.
import sys
import time
from keras.utils import Sequence, to_categorical, multi_gpu_model
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Flatten
from keras.layers import Embedding
from keras.layers.convolutional import Conv1D
from keras.layers.convolutional import MaxPooling1D
from sklearn.model_selection import KFold
from keras.preprocessing.sequence import pad_sequences
import numpy as np
import random
from pymongo import MongoClient
from bson import ObjectId
from sklearn.metrics import classification_report, confusion_matrix

class Custom_Generator(Sequence) :

    def __init__(self, document_ids, batch_size) :
        self.document_ids = document_ids
        self.batch_size = batch_size

    def __len__(self) :
        return (np.ceil(len(self.document_ids) / float(self.batch_size))).astype(np.int)

    def __getitem__(self, idx) :
        client = MongoClient(port=27017)
        db = client[database]
        document_ids = self.document_ids[idx * self.batch_size : (idx+1) * self.batch_size]
        query_results = db[collection].find({'_id': {'$in': document_ids}})
        batch_x, batch_y = [], []
        for result in query_results:
            kmer_list = result['kmers'].split(',')
            label = result['label']
            x = [x for x in kmer_list if len(x) > 0]
            if len(x) < 1:
                continue
            batch_x.append(x)
            one_hot_y = to_categorical(label, 5)
            batch_y.append(one_hot_y)
        batch_x = pad_sequences(batch_x, maxlen=126, padding='post')
        client.close()
        return np.array(batch_x), np.array(batch_y)

# MongoDB database, collection, and document ids of collection
database = 'db'
collection = 'collection_subset2'
docids_file = 'docids_collection_subset2.txt'
id_ls = []
# Convert docids strings to MongoDB ObjectID
with open(docids_file) as f:
    for line in f:
        id_ls.append(ObjectId(line.strip()))
random.shuffle(id_ls)

# Model
model = Sequential()
model.add(Embedding(65521, 100, input_length=126))
model.add(Conv1D(filters=25, kernel_size=5, activation='relu'))
model.add(MaxPooling1D(pool_size=2))
model.add(Conv1D(filters=30, kernel_size=3, activation='relu'))
model.add(MaxPooling1D(pool_size=2))
model.add(Flatten())
model.add(Dense(1000, activation='relu'))
model.add(Dense(5, kernel_initializer="normal", activation="softmax"))
metrics=['accuracy'])
parallel_model = multi_gpu_model(model, gpus=2)
parallel_model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

seed = 7
batch_size = 50000

# Currently training with 5-fold CV. Will only use single test train split
# on the full-scale dataset.
kfold = KFold(n_splits=5, shuffle=True, random_state=seed)
kfold_stats = {}
accuracy_ls = []
val_accuracy_ls = []
confusion_ls = []
for fold_idx, (train_idx, test_idx) in enumerate(kfold.split(id_ls)):
    ids_train = np.array(id_ls)[train_idx].tolist()
    ids_test = np.array(id_ls)[test_idx].tolist()
    training_batch_generator = Custom_Generator(ids_train, batch_size)
    validation_batch_generator = Custom_Generator(ids_test, batch_size)
    print('Number of train files: %d' % len(ids_train))
    print('Number of test files: %d' % len(ids_test))
    start = time.time()
    history = parallel_model.fit_generator(
        generator=training_batch_generator,
        steps_per_epoch = int(len(ids_train) // batch_size),
        epochs = 5,
        verbose = 2,
        validation_data = validation_batch_generator,
        validation_steps = int(len(ids_test) // batch_size),
        use_multiprocessing=True
    )
    sys.stderr.write("time to train model (seconds): %d\n"%(time.time() - start))
    sys.stderr.flush()
    print(history.history)
    fold_name = 'kfold_%s' % str(fold_idx)
    kfold_stats.update({fold_name: history.history})
    accuracy_ls.extend(history.history['accuracy'])
    val_accuracy_ls.extend(history.history['val_accuracy'])
    parallel_model.save('model_output_kfold_%s.h5' % str(fold_idx))
    print("Kfold %s finished" % str(fold_idx))
    Y_pred = parallel_model.predict_generator(validation_batch_generator)
    y_pred = np.argmax(Y_pred, axis=1)
    y_true = np.concatenate([np.argmax(batch[1], axis=1) for batch in validation_batch_generator])
    print('Confusion Matrix')
    conf = confusion_matrix(y_true, y_pred)
    print(conf)
    confusion_ls.append(conf)
    print('Classification Report')
    target_names = ['Class_name_1', 'Class_name_2', 'Class_name_3', 'Class_name_4', 'Class_name_5']
    report = classification_report(y_true, y_pred, target_names=target_names)

I would suggest using as little data as possible to help speed up the process. You are right you don't need the database. Although it does help with the problem of organizing the data it may create some latency.

Thanks @MichaelHearn. It's true, I should do some learning curves to see how much I need.

First of all, you should add the argument workers = n in the fit generator call. n should be bigger than 1 to prefetch data. As your data processing requires the data be taken from a server or port, you should do pre fetching data as that would fetch the next data while GPU is processing.
If you call fit_generator with workers > 1 , use_multiprocessing=True , we will prefetch queue_size batches.
Source: https://github.com/keras-team/keras/issues/12847
Secondly, as @MichaelHearn mentioned, you should plot a graph to see how many data is needed. You task should not require several billion data samples. A couple hundred thousand data should be enough. If the model is not getting a good accuracy from a couple hundred thousand data samples, perhaps you can try changing up the model architecture instead of adding more data. Maybe you can add drop out layers.
Hope I can help you.

Thanks for the advice for prefetching @ClementHui. I thought creating a parallel model and including multiprocessing arguments were redundant, but now I see how they work. Concerning dropout layers, I thought those were just to prevent overfitting. So far I have not seen that problem as my train and test performance is closely matched. Also, I edited my question with some background to hopefully make it more clear why I think my training set needs to be so large. However, I could be wrong and each class may be distinct enough that I can get by with less. I will do some learning curves. Thanks!

If the genomes are so different, you may try choosing the most important part of the genome to input to the network, instead of using all of it. Maybe you can do some kind of input selection.


text:
Is there an efficient way of determining the layers with the best performance as feature extractors in GoogleNet?
I am using a caffe model of pre-trained GoogleNet trained on ImageNet from here for image retrieval task (place recognition, more specifically).

I would like to know the layer with best performance in feature extraction. Its official paper suggests that:

The strong performance of shallower networks on this task suggests
  that the features produced by the layers in the middle of the network
  should be very discriminative.

There is also a project deepdream suggests that:

The complexity of the details generated depends on which layer's
  activations we try to maximize. Higher layers produce complex
  features, while lower ones enhance edges and textures, giving the
  image an impressionist feeling.

Searching the web, I found a github page suggesting pool5/7x7_s1layer as feature extractor without specific convincing reasons.
What I am doing now is quite cumbersome in which I extract features from each individual layer, apply scipy euclidean distance measurement to find a query in the reference database and  the judgment is based on precision-recall curve and my top 3 results are as follows for one dataset:

inception_3a/3x3
inception_4a/5x5
inception_4b/output

Considering large number of convolutional layers in GoogleNet, my approach is undoubtedly quite inefficient and can be changed to another dataset!
Can anyone suggest an efficient way to figure out the layers with the best performance as feature extractors in GoogleNet?

So, given a trained model, are you trying to understanding which of the layers of the pre-trained network extract the most "relevant" features?

That’s exactly what I’m looking for in googlenet or if there’s any rule of thumb for all networks

Maybe you're looking for something like "layer-wise relevance propagation", which is an explainable AI technique.

not LRP specifically! but more of using specific layers of GoogleNet as holistic feature extraction for problems other than image classification or object detection! What I work is, for example, place recognition problem in which I investigate layers of GoogleNet to figure out ones is more efficient finding more query images in reference database!

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Choosing a policy improvement algorithm for a continuing problem with continuous action and state-space
I'm trying to decide which policy improvement algorithm to use in the context of my problem. But let me emerge you into the problem
Problem
I want to move a set of points in a 3D space. Depending on how the points move, the environment gives a positive or negative reward. Further, the environment does not split up into episodes, so it is a continuing problem. The state space is high-dimensional (a lot of states are possible) and many states can be similar (so state aliasing can appear), also states are continuous. The problem is dense in rewards, so for every transition, there will be a negative or positive reward, depending on the previous state.
A state is represented as a vector with dimension N (initially it will be something like ~100, but in the future, I want to work with vectors up to 1000).
In the case of action, it is described by a matrix 3xN, where N is the same as in the case of the state. The first dimension comes from the fact, that action is 3D displacement.
What I have done so far
Since actions are continuous, I have narrowed down my search to policy gradient methods. Further, I researched methods, that work with continuous state spaces. I found a deep deterministic policy gradient (DDPG) and the Proximal Policy Gradient (PPO) would fit here. Theoretically, they should work but I'm unsure and any advice would be gold here.
Questions
Would those algorithms be suitable for the problem (PPO or DDPG)?
There are other policy improvement algorithms that would work here or a family of policy improvement algorithms?

You could try https://arxiv.org/pdf/1804.08617v1.pdf. It's from Deepmind (the authors of DDPG). They also provided code.

Thanks @Schach21, every piece is a valueable one.

I'm using my own implementation of A2C (Advantage Actor Critic) in an industrial application based on Markov Process (present state alone provides sufficient knowledge to make an optimal decision). It's simple and versatile, its performance proven in many different applications. The results so far have been promising.
One of my colleagues had issues with solving a simple task of mapping images to coordinates with OpenAI's Stable Baselines implementations of PPO and TRPO. Hence I'm biased against this framework.
My suggestion is to try the simplest model and if that doesn't satisfy your expectations for performance, then try something fancier. Once you've made a pipeline for learning, switching to a different algorithm is relatively time inexpensive.
Here is a list of algorithms for continuous action and state space from the wikipedia article about RL:

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
What are the strategies for computationally heavy environments or long-time waiting environments?
I have an environment that is computationally heavy (takes several seconds to get a reward and next state). This limits reinforcement capability, due to poor sampling of the problem. There is any strategy that could be used to address the problem (e.g. If I can use the environment in parallel, then I could use a multi-agent approach)

Mltiple environments, installing some form of reward shaping or prior knowledge into the problem?

@FourierFlux
In terms of multiple environments - then how you would integrate them? Average updates like in A3C alg. ?

You could use Ray RLlib. It has support for parallel environments, even over multiple GPUs and compute nodes.


text:
Reinforcement Learning method suitable for a large discrete action space with high sample efficiency
Consider the following problem.
We have a process, that generates $N$ stones (e.g. 2000) in one batch $b$. Every pebble has state $s_{i}^b$ and reward $s_i^b$. After choosing one pebble $i$ from the $N$, we start sampling again using the chosen pebble as a starting point and we generate the next batch $b+1$. The state $s_i^b$ is a vector of real-values and the reward $r_i^b$ is a real value.
The problem is to choose pebbles so that we maximize reward $r_i^b$ in long term. Because depending on how we choose the pebble, we can sample around the region that gives a better or worse reward $r$.
During each new batch, we make one selection of one pebble (so actions can from $i, \dots, N$. We have access to the previous $m$ batches (e.g. through replay buffer) with their rewards and states.
In short, it looks like this:

Chose randomly the first pebble from which we start sample;
We start sampling from the chosen pebble in the current batch;
We sample $N$ pebbles from a process, each pebble have a state $s_i^b$ and reward $r_i^b$;
We can chose one pebble from $i \dots N$ as action $a_i^b$ based on state $s_i^b$ and reward $r_i^b$;
Go to point 1 and repeat;

For example, at the moment, I choose in a given batch $b$ pebble with max reward $r_i^b$, so
$$i = \underset{i}{\mathrm{argmax}}\, r_i^b$$ and then use $a_i^b$ for a the current batch $b$.
But what I want is to choose:
$$i = \underset{i}{\mathrm{argmax}}\, \underset{b}{E}[R_i^b | s_i, a_i]$$
Graphically speaking:
Assuming one Batch (N) is 30
P - pebble, P - chosen pebble
batch 1: PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
batch 2: PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
batch 3: PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
batch 4: PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
batch 5: PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
So, if I have a batch $N$, when I choose one element from the batch as an action, so the expected reward is the highest in long term, and start the sampling again from it. So only one element per batch can be chosen. And only choice of the one pebble per batch does affect the sequence in the next batch, but not inside the current batch.
The problem is, what Reinforcement Learning algorithm to use, when we choose only one item from N. And the one choice affect the whole sampled sequence in the next batch. For example in batch 1 to 4, the reward can be very low, and in batch 5 the reward is super high, if we chose wisely the pebbles in 4 previous batchs.

Please could you give more details about the environment and the goal of the agent, what you have so far is not clear. For instance it is not clear whether you make one selection for each new batch, and it is not clear whether there is any data that would help the agent select a high reward pebble, or why the state $S_t$ is associated with a choice of pebble (or what that means in terms of predicting next choice, or impact on next state).

@NeilSlater Tried to make it more precise, if you can judge if there's enough information or not, comment please

In the title, you wrote "continuous action space", but it seems that you have a discrete action space, i.e. one "pebble" (or stone) from some set of $N$ actions (which you call a "batch", which may be confusing). Am I misunderstanding your description or is it a typo?

@nbro
Yes, corrected - should be large discrete

Sorry it is still not very clear. (1) It is not clear whether time steps are same as batches - do you make only one decision per batch. (2) It is not clear what the state means or is used for - most importantly, does selecting a pebble that has a state $s^b_i$ have any impact on the next batch $b+1$? (3) Am I correct in thinking that the action choice is a value of $i$ - i.e. selecting one specific pebble from the batch, and after which there is another time step, with a new batch? However, your step 3 implies that you can select more than one pebble per batch?

Also, your objective looks wrong, since it is maximising reward over a single batch - which you can already do by selecting by the reward that you already know. You need to involve time steps here in some way, and to explain how the action choice at one time step influences what happens in later time steps. If there is no control over the sequence based on actions that you take, then you probably do not have a reinforcement learning problem, but you may still have a related problem e.g. k-armed bandit.

@NeilSlater

If there is no control over the sequence based on actions that you take, then you probably do not have a reinforcement learning problem, but you may still have a related problem e.g. k-armed bandit.
I have only control over the point between batches, but not the sequence in the batch.
I'll correct the stack in a moment

Is the information about the impact of your choice of pebble on the next batch encoded into the pebbles state? So far I don't see any purpose for the state value?

@NeilSlater
Yes, it's a real-valued 1xm vector. So during every batch we get a N x m matrix, where N is the batch size.

There will never be good sample efficiency, it's kind of an oxymoron in RL because dynamics can be arbitrarily sharp and the NN approximater will need to take that into account or be structured in a way which incorporates known dynamics.

My understanding of your environment is:

The batch number $b$ is the same thing as a time step $t$. Each batch is associated with a single static representation of the environment, the agent makes one decision, then receives a reward and a next state. I am using $t$ instead of $b$ to match the usual name seen in RL.

There is a generator which can be in a state $s_t$, initially unknown for $s_0$.

Each time step, $t$, the generator creates a batch of "pebbles". The generator state $s_t$ determines the output of the generator, and is the only non-random influence on the contents of each batch - it controls the possible rewards plus the possible next states.

Selecting a specific pebble from the batch returns an immediate reward $r_{t+1}$ plus sets the next state $s_{t+1}$. This is the agent's action, and it can choose any pebble from the batch as its action $a_t$.

The agent can see the values of $r_{t+1}$ and $s_{t+1}$ associated with each pebble before making its selection.

This is a slightly unusual setup for an MDP, but I think it is still a valid MDP, and the expected return can still be maximised using reinforcement learning. One important detail is that although you have a discrete list of actions in each batch, the action index values look like they are meaningless. Your action choice is really to choose the next state $s_{t+1}$ from a presented list of available states. Your action space is therefore continuous, not discrete, even though at each step you are selecting from a discrete set of actions.
The environment design is different enough from standard that most off-the-shelf RL agent libraries will not work for you. However, you can take advantage of this knowledge of the action space, and the fact that there is no other meaningful state than that selected by the agent when it chooses a pebble, to learn state values efficiently.
I would suggest you use a variant of Q-Learning, based on the "afterstate" values that you are selecting. You can train a neural network to approximate the state value function $\hat{v}(s,\theta)$ and you have a choice whether to use discounted returns or an average reward setting. When deciding the greedy target policy, you will want to select according to
$$\pi = \text{argmax}_i (r_i + \gamma \hat{v}(s_i,\theta))$$
for discounted return. For Q learning, technically you should also store the whole batch output in experience replay, because the TD target will be
$$g = \text{max}_i (r_i + \gamma \hat{v}(s_i,\theta))$$
and you won't know what this max will be later at the time of storing the memory. There may be ways around that - for instance you could use SARSA updates based on the actual action taken, or you could store the value of $g$. However, these would be less sample efficient and you would need to discard the memory at a faster rate, before it became too out of date with respect tothe current policy.
I think an average reward will be closer to your stated goal of generating highest expected reward from each individual batch, but I am not 100% certain how to set up the policy for that. Whilst a discounted return may end up preferring a high immediate reward in some circumstances. However, you may be able to get near identical behaviour by setting $\gamma$ high enough (e.g. $0.99$ or higher) in the more familiar discounted return setting.
The efficiency of this approach will depend on how easy it is for the agent to learn the mapping between states and the quality of the next batch. However, you should have a higher sample efficiency when selecting by afterstate, because the agent does not need to learn separately how actions relate to states.


text:
What is the "semantic level"?
I am reading the paper Hierarchical Attention-Based Recurrent Highway Networks for Time Series Prediction (2018) by Yunzhe Tao et al.
In this paper, they use several times the expression "semantic levels". Some examples:

HRHN can adaptively select the relevant exogenous features in different semantic levels
the temporal information is usually complicated and may occur at different semantic levels
The encoder RHN reads the convolved features $(w_1,w_2,···,w_{T−1})$ and models their temporal dependencies at different semantic levels
Then an RHN is used to model the temporal dependencies among convolved input features at different semantic levels

What is the semantic level?

In language theory, there are generally several admitted levels that can be studied in relation with one another or independently. The semantic level is the one dealing with the meaning of the text ("semantic" comes from the greek and means "to signify"). The semantic level is therefore generally independent from the syntax and even the language used to convey the message.
Here is an interesting picture I found on the internet to illustrate my point.

EDIT: I took some time reading the paper. I think "semantic levels" refers here to the different neural networks layers used for the exogenous features.
Here is a modified version of their figure I've drawned to make it clearer:

In particular, from what I have understood so far, the attention coefficients apply to the whole semantic level (which I find not really clearly indicated on their figure)
The LHS of their figure would then be better described by this new one:

Hope this helps!

I think it would be nice if you could also explain the meaning of the expression "semantic level" in the specific context of the paper that the OP is quoting.

@nbro You're right, I read the question too fast. I took some time reading the paper. I think "semantic levels" refers to the possible interactions between the different layers of the neural network. Each layer of the neural network representing possibly a semantic level. The architecture of the RHN seems (does it?) to enable such direct interactions (cf. RHS of fig. 2 page 3 of the paper). Not too sure about this, I'm thrilled to see other's replies as I find the subject really interesting! :-)

You should edit your answer to include any new details you think are relevant to the question. Comments are only temporary and can be deleted later.

In the paper the authors mention that the first time they use RHN is to summarize the exogenous data into different semantics at different levels. So now, whit what @Jenba have said, I understand that the term "semantic levels" refers to the layers RHN shown below in fig. 2 at the bottom in green. Each layer is a different semantic tha is in a different level.

Yes I think we finally figured this out. I modified my original response with two new drawings to make it clearer. :-)


text:
Reinforcement learning for a 2D game involving two players
I'd like to create an AI for a 2D game involving two players fighting against each other. The map look something like this (The map is a NxN array somehow randomly generated):

Basically the players can look for objects such as weapons located on platforms, shoot at each other to cause damages etc. The output actions are therefore limited to a few such as going up, left, right, down, shooting angle, shooting boolean...
I'm wondering if Reinforcement Learning using a neural network is a good approach to the problem. If so, how should I proceed for the learning phase? Should I force the AI to compete with a weaker version of itself at each iteration? Would it be computationally reasonable to train on a 4Gb GPU?
Thanks in advance for your advice !

Why would you want to train it against a weaker version of itself if you can train it against the current version of itself?


text:
How to change the architecture of my simple sequential model
I'm new to Deep Learning with Keras. With some tutorials online for cat vs non-cat classification, I was able to compile this simple architecture for my own classification problem. However, my target application is fire detection which essentially might have semantic differences with cats.
After training, I realized this model is accurate when the fire scene is simple and visible, but if many objects inside or fire is a bit smaller, it fails to detect. So I thought maybe I can change the architecture by increasing the complexity.
First thing came into my mind was increasing the first layer filters from 32 to 64 by changing to model.add(Conv2D(64, kernel_size = (3, 3), activation='relu', input_shape=(IMAGE_SIZE, IMAGE_SIZE, 1)))
Is it going to help? What are other best practices to change the architecture? How about increasing the number of kernels to kernel_size = (5, 5) or adding one more layer or even changing the images from grayscale to colored?
Here is my original training code:
from keras.models import Sequential, load_model
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras.layers.normalization import BatchNormalization
from PIL import Image
from random import shuffle, choice
import numpy as np
import os

IMAGE_SIZE = 256
IMAGE_DIRECTORY = './data/test_set'

def label_img(name):
  if name == 'cats': return np.array([1, 0])
  elif name == 'notcats' : return np.array([0, 1])

def load_data():
  print("Loading images...")
  train_data = []
  directories = next(os.walk(IMAGE_DIRECTORY))[1]

  for dirname in directories:
    print("Loading {0}".format(dirname))
    file_names = next(os.walk(os.path.join(IMAGE_DIRECTORY, dirname)))[2]

    for i in range(200):
      image_name = choice(file_names)
      image_path = os.path.join(IMAGE_DIRECTORY, dirname, image_name)
      label = label_img(dirname)
      if "DS_Store" not in image_path:
        img = Image.open(image_path)
        img = img.convert('L')
        img = img.resize((IMAGE_SIZE, IMAGE_SIZE), Image.ANTIALIAS)
        train_data.append([np.array(img), label])

  return train_data

def create_model():
  model = Sequential()
  model.add(Conv2D(32, kernel_size = (3, 3), activation='relu',
                   input_shape=(IMAGE_SIZE, IMAGE_SIZE, 1)))
  model.add(MaxPooling2D(pool_size=(2,2)))
  model.add(BatchNormalization())
  model.add(Conv2D(64, kernel_size=(3,3), activation='relu'))
  model.add(MaxPooling2D(pool_size=(2,2)))
  model.add(BatchNormalization())
  model.add(Conv2D(128, kernel_size=(3,3), activation='relu'))
  model.add(MaxPooling2D(pool_size=(2,2)))
  model.add(BatchNormalization())
  model.add(Conv2D(128, kernel_size=(3,3), activation='relu'))
  model.add(MaxPooling2D(pool_size=(2,2)))
  model.add(BatchNormalization())
  model.add(Conv2D(64, kernel_size=(3,3), activation='relu'))
  model.add(MaxPooling2D(pool_size=(2,2)))
  model.add(BatchNormalization())
  model.add(Dropout(0.2))
  model.add(Flatten())
  model.add(Dense(256, activation='relu'))
  model.add(Dropout(0.2))
  model.add(Dense(64, activation='relu'))
  model.add(Dense(2, activation = 'softmax'))

  return model

training_data = load_data()
training_images = np.array([i[0] for i in training_data]).reshape(-1, IMAGE_SIZE, IMAGE_SIZE, 1)
training_labels = np.array([i[1] for i in training_data])

print('creating model')
model = create_model()
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
print('training model')
model.fit(training_images, training_labels, batch_size=50, epochs=10, verbose=1)
model.save("model.h5")


text:
Semantic issues with predictions made by my trained model
I'm new to Deep Learning. I used Keras and trained a inception_resnet_v2 model for my binary classification application (fire detection). As suggested from my previous question of a non-X class, I prepared a dataset of 8000 images of fire, and a larger dataset for non-fire (20,000 random images) to make sure the network also sees images of non-fire to perform classification.
I trained the model, but now when trying to load the model and pass images of fire and non-fire ones, it shows same result for all of them:
[[0. 1.]]
[[0. 1.]]
[[0. 1.]]
[[0. 1.]]
[[0. 1.]]

What is going wrong? Am I doing anything wrong? Should I get the result another way?
===============================================
I know it's not SO, but this is my prediction code in case it matters:
from __future__ import print_function
from keras.models import load_model, model_from_json
import cv2, os, glob
import numpy as np
from keras.preprocessing import image

if __name__ == '__main__':
    model = load_model('Resnet_26_0.79_model_weights.h5')

    os.chdir("test")
    for file in glob.glob("*.jpg"):
        img_path = file
        img = image.load_img(img_path, target_size=(300, 300))
        x = image.img_to_array(img)
        x = np.expand_dims(x, axis=0)

        dictionary = {0: 'non-fire', 1: 'fire'}

        results = model.predict(x)
        print(results)
        predicted_class= np.argmax(results)
        acc = 100*results[0][predicted_class]
        print("Network prediction is: file: "+ file+", "+dictionary[predicted_class]+", %{:0.2f}".format(acc))

And here is the training:
from keras.applications.inception_resnet_v2 import InceptionResNetV2, preprocess_input
from keras.preprocessing.image import ImageDataGenerator
from keras.layers import Dense, Activation, Flatten, Dropout
from keras.models import Sequential, Model
from keras.optimizers import SGD, Adam
from keras.callbacks import ModelCheckpoint
from keras.metrics import binary_accuracy
import os
import json
#==========================
HEIGHT = 300
WIDTH = 300
TRAIN_DIR = "data"
BATCH_SIZE = 8 #8
steps_per_epoch = 1000 #1000
NUM_EPOCHS = 50 #50
lr= 0.00001
#==========================
FC_LAYERS = [1024, 1024]
dropout = 0.5

def build_finetune_model(base_model, dropout, fc_layers, num_classes):
    for layer in base_model.layers:
        layer.trainable = False

    x = base_model.output
    x = Flatten()(x)
    for fc in fc_layers:
        # New FC layer, random init
        x = Dense(fc, activation='relu')(x)
        x = Dropout(dropout)(x)

    # New layer
    predictions = Dense(num_classes, activation='sigmoid')(x)
    finetune_model = Model(inputs=base_model.input, outputs=predictions)
    return finetune_model

train_datagen =  ImageDataGenerator(preprocessing_function=preprocess_input, rotation_range=90, horizontal_flip=True, vertical_flip=True
                                    ,validation_split=0.2)
train_generator = train_datagen.flow_from_directory(TRAIN_DIR, target_size=(HEIGHT, WIDTH), batch_size=BATCH_SIZE
                                                    ,subset="training")
#split validation manually
validation_generator = train_datagen.flow_from_directory(TRAIN_DIR, target_size=(HEIGHT, WIDTH), batch_size=BATCH_SIZE,subset="validation")

base_model = InceptionResNetV2(weights='imagenet', include_top=False, input_shape=(HEIGHT, WIDTH, 3))

root=TRAIN_DIR
class_list = [ item for item in os.listdir(root) if os.path.isdir(os.path.join(root, item)) ]
print ("class_list: "+str(class_list))

finetune_model = build_finetune_model(base_model, dropout=dropout, fc_layers=FC_LAYERS, num_classes=len(class_list))

adam = Adam(lr)
# change to categorical_crossentropy for multiple classes
finetune_model.compile(adam, loss='binary_crossentropy', metrics=['accuracy'])

filepath="./checkpoints/" + "Resnet_{epoch:02d}_{acc:.2f}" +"_model_weights.h5"
checkpoint = ModelCheckpoint(filepath, monitor=["val_accuracy"], verbose=1, mode='max', save_weights_only=False)
callbacks_list = [checkpoint]

history = finetune_model.fit_generator(train_generator, epochs=NUM_EPOCHS, workers=BATCH_SIZE,
                                    validation_data=validation_generator, validation_steps = validation_generator.samples,
                                       steps_per_epoch=steps_per_epoch,
                                       shuffle=True, callbacks=callbacks_list)

I think you may have a class imbalance problem here, if I am reading your output correctly. You have 20,000 negative examples, but only 8000 positive ones, and you are minimizing binary cross entropy without re-weighting the examples, so your model can achieve a low-ish loss just by consistently outputing a value close to 0. This forms a local optima in the search space for the model.
To fix this, you could try to optimize some other loss function that is more sensitive to class imbalances, or, likely more productively, you could just use an equal number of examples for each class.

I've seen examples (cat vs non-cat) where they used 5K for non-cats and 1600 for cats. But what combo of activation/loss shall I use? Is it OK to change the sigmoid to softmax and still have the binary_crossentropy? (like the cat exmaple).

@TinaJ whether you can handle class imbalance will really depend on the problem you are working on. If the classes are difficult to separate, then it will be a problem. If not, it probably won't be. I think the choice of activation function shouldn't make a big difference here.

My impression was the more non-object I have, the better the accuracy. Didn't know the size imbalance can also be a negative factor!

@TinaJ an extreme case that might help with the intuition: Imagine we have a dataset of blood test results, where 99.99% of the results are negative for a disease, and 0.01% are positive. A model can achieve an extremely low cross-entropy loss value by claiming everything is negative. It will be right almost always, but the model is not a useful one.


text:
Which deep neural networks are appropriate for the detection of bombs?
This is a follow-up question from my previous post here about explosion detection. I gathered a dataset of explosions. As I'm new to Deep Learning in Keras, I'm trying to see what architecture best suits this problem, given that here we have a cloud of smoke/fire as opposed to an object. Any suggestions?
For instance, I've learned about Faster RCNN or RetinaNet, but that is mostly for object detection. Is it going to be better than say a basic ResNet50? And here real-time prediction requirements are not an issue. So shall I assume a heavier model (e.g. NASNet Large or a Resnet-152 model) is better than a basic ResNet-50 model?

"I gathered a dataset of explosions", have you found it on the web or have you manually created it? If you found it on the web, maybe you can give an answer to your other question.

No I created a small dataset myself from youtube! Had a hard time.

In case you do not find a specific architecture suited for your problem, I would suggest you start with the simplest architecture. If it doesn't perform well enough, try with a more complex one, and so on.


text:
Why is this ResNet50 misclassifying objects?
I'm new to Deep Learning, and I have some conceptual problems. I followed a simple tutorial here, and trained a model in Keras to do image classification on 10 classes of logos. I prepared 10 classes with each class having almost 100 images. My trained Resnet50 model performs exceptionally great when the image is one of those 10 logos, with 1.00 probability. But the problem is if I pass a non-logo item, a random image totally unrelated visually, still it marks it as one of those logos with close to 1.00 probability!
I'm confused. Am I missing anything? Why is this happening? How to find a solution? I need to find logos in video frames. But right now, with a high possbility each frame is marked as a logo!
Here is my simple training code:
def build_finetune_model(base_model, dropout, fc_layers, num_classes):
    for layer in base_model.layers:
        layer.trainable = False

    x = base_model.output
    x = Flatten()(x)
    for fc in fc_layers:
        # New FC layer, random init
        x = Dense(fc, activation='relu')(x)
        x = Dropout(dropout)(x)

    # New softmax layer
    predictions = Dense(num_classes, activation='softmax')(x)
    finetune_model = Model(inputs=base_model.input, outputs=predictions)
    return finetune_model
finetune_model = build_finetune_model(base_model, dropout=dropout, fc_layers=FC_LAYERS, num_classes=len(class_list))
adam = Adam(lr=0.00001)
finetune_model.compile(adam, loss='categorical_crossentropy', metrics=['accuracy'])
filepath="./checkpoints/" + "ResNet50" + "_model_weights.h5"
checkpoint = ModelCheckpoint(filepath, monitor=["acc"], verbose=1, mode='max')
callbacks_list = [checkpoint]

history = finetune_model.fit_generator(train_generator, epochs=NUM_EPOCHS, workers=8,
                                       steps_per_epoch=steps_per_epoch,
                                       shuffle=True, callbacks=callbacks_list)

plot_training(history)

This sounds like a classic example of training data that is not representative of the input your network will be receiving. Since the network has only seen input data that is expected to produce a value of 1.00 at one of the nodes, after significant training that's what it will do for all inputs, because it would be punished if it ever did otherwise. This is a really common problem, that has many solutions, but this answer from a while back has some good suggestions on how to solve for input entirely out of the scope of the problem: https://stackoverflow.com/a/52831580/9546874

Too add to @Recessive's answer -- answer (2) in that link is good, but to make it work you also need some training data which doesn't contain logos! Since you have a softmax final layer, I guess your labels are (currently) vectors which are all 0 except for a single 1. In a training image with no logo, it will be all zeros.

Thanks guys. As I was thinking myself, looks like I should really add another class "unknown". But the problem is how big it should be? We can not put whatever on earth as a non-logo class :-/

@TinaJ Another alternative is to use an object detection model instead - one that answers the question "of the objects I know, how many appear in this image, and which?" compared to image classification, which instead asks "of the objects that I know, which is the one in this image most similar to?"

@gmds can you describe more?! What do you mean object detection model?

Your problem is a classification problem. If you are following the tutorial, it is using the ResNet50 network, which is a convolutional neural network with one fully connected layer at the end. At the end the activation function is softmax. Detailed description of the activation function can be found here: Softmax function explained

Basically, softmax increases the difference between the higher probability and lower probability. It also limits the output between 0 and 1.
Problem Origin
Due to the nature of the softmax function, it always chooses the best one and enlarge the value to be a value near one, even if the range of the output predictions is very small like 0-0.1. Also you training data only have the data of the 10 logos labelled, so if the network see unseen images with no logo it recognizes, it predicts the one with the most similarity. If you want to classify images with no logos in it, you should add an extra class in the training dataset and also the code to train the network to learn to classify images which is not in the 5 class into a separate maybe called unlabeled. Hope I can help you and have a nice day.

Thanks anyways. As I was thinking myself, looks like I should really add another class "unknown". But the problem is how big it should be? We can not put whatever on earth as a non-logo class :-/

You should try putting at least the same amount of unknown data as the other class each have. If it doesn't work, put more of the unknown data until it works. Experimenting and trying is the key. Hope it helps

@TinaJ  You could use a GAN like logic to produce random non-logo images (without training the generator of course)

@Fnguyen that's also interesting...hopefully if the images are not very random! Needs to be a bit realistic also. Any code repository or samples for that?

@TinaJ There are tons of examples if you Google GAN. I'd recommend machinelearningmastery because he has the whole Keras code. If you want it to be somewhat realistic you could train the generator a bit so it's not just random.


text:
How many layers exists in my neural network?
I have a neural network model defined as below. How many layers exist there? Not sure which ones to count when we are asked about the number.
def create_model():
    channels = 3
    model = Sequential()
    model.add(Conv2D(32, kernel_size = (5, 5), activation='relu', input_shape=(IMAGE_SIZE, IMAGE_SIZE, channels)))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(BatchNormalization())
    model.add(Conv2D(64, kernel_size=(3,3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(BatchNormalization())
    model.add(Conv2D(128, kernel_size=(3,3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(BatchNormalization())
    model.add(Conv2D(256, kernel_size=(3,3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(BatchNormalization())

    model.add(Conv2D(64, kernel_size=(3,3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(BatchNormalization())
    model.add(Dropout(0.2))
    model.add(Flatten())
    model.add(Dense(256, activation='relu'))
    model.add(Dropout(0.2))
    model.add(Dense(128, activation='relu'))
    model.add(Dense(2, activation = 'softmax'))

    return model

I think the answer to this question is indeed subjective because some people may or not consider the activations, dropout and batch normalization separate layers. However, convolutions, pooling and dense are almost always considered standalone layers. You can also use model.layers to get the layers of the network, according to Keras.

Exactly. My impression was I should just count CONV layers!

If this is a homework question, I would provide some comments regarding this issue. By the way, you may also say that it may depend on the implementation. For example, in Keras, the activations may or not always be implemented as a separate layer (note that I actually don't know if that's the case or not)!

If its a subjective question, how about you list all the layers i.e, 5 Convolutional Layers, 2 Dense Layers and so on. Another widely used practice is to define the network with blocks where a Convolutional Block will include Conv2D, MaxPooling, BatchNormalizarion and Flatten. However, if you want a number according to how the network/graph will be structured, then number of layers only includes Conv and Dense.

tl;dr I'd say your model has 8 layers (5 conv, 3 dense), however a lot of people count layers in other ways. From what I've seen this is by far the most conventional way for counting layers.

Justification
This is an interesting question because its quite subjective. In most cases only the convolutional and dense layers would count from your network. Bach norm, dropout and flatten are usually considered as operations to other layers rather than layers of their own (much like activation functions).
Note: It is debatable whether or not pooling layers are considered to be layers (as they have no trainable parameters) but in most cases they are not considered to be so.
Note 2: Batch norm, on the other hand, isn't usually considered a layer even though it has trainable parameters. Clearly the authors didn't introduce it as a layer, but as a way to normalize, shift and scale the inputs of a layer. This is apparent in some of the examples below which don't count batch norm as an actual layer.
Note 3: Conventionally all networks are considered to have [at least] one input layer but it doesn't count as a layer.

Examples
Some examples that follow this reasoning when counting layers are the following. I'll also write the pooling layers in each, but they clearly aren't considered as layers be the authors. When available I'll also write the number of layers that keras registers from their official implementations:
The ResNet-50 architecture has 50 layers (49 conv, 2 pool, 1 dense), however keras registers it as 177 layers. ResNets also use batch normalization after each convolution (so 49 batch norms in total), but clearly don't count them as layers.
The Resnet-34 has 34 layers (33 conv, 2 pool, 1 dense). Like the previous, this also uses batch norm but doesn't count it.
VGG-19 has 19 layers (16 conv, 5 pool 3 dense). Keras registers this as 26 layers.
AlexNet is considered to have 8 layers (5 conv, 3 pool, 3 dense).


text:
How to use AI for language recognition?
Given an audio track, I'm trying to find a way to recognize the audio language. Only within a small set (e.g. English vs Spanish). Is there a simple solution to detect the language in a speech?

If you are finding a tool, this question maybe off topic. @nbro

No tool. A simple solution.

Google has an API you can use. https://cloud.google.com/translate/. Their API can translate audio to text. They also have an API for converting speech to text. The language detection feature should let you detect the language in the resulting text. They have client libraries for the most popular programming languages.

Yeah that I know. But then the problem of language detection still remains.

Google translate can detect the langauge for you as well

You can see a python example of this at https://pypi.org/project/googletrans/

Umm good. But something possibly non cloud.


text:
How to generate the original image from feature set?
We all know that using CNN, or even simpler functions, like CLD or EHD, we can generate a set of features out of images.
Is there any ways or approaches that given a set of features, we can somehow generate a corase version of the original image that was given as input? Maybe a gray-scale version with visible objects inside? If so, what features do we need?

Look into deconvolution, it minimizes the L2 differnce of a convolution given a filter and activation map, and then you can approximate inverses of the activations (though understand you do lose information like at RELU in the negative region) so itll only show parts. But yes you can construct pieces of image given the features and featurizer

Can you provide more details? Like a starter reference?

The model (that I know of) which most resembles your description is the auto-encoder, which is trained to learn a compact representation (a vector) of the input, which can later be used to reconstruct the original input. In a certain way, this compact representation (implicitly) encodes the most important features of the input. In particular, you may be looking for denoising auto-encoders.

Ummm auto encoders or GANs are probably the way. Can you describe what they are? I'm new.

@TinaJ In the paper that introduced the denoising auto-encoder (that I am linking you to in my answer), Extracting and Composing Robust Features with Denoising Autoencoders, the basic auto-encoder is also described in section 2.2  The Basic Autoencoder. Have a look at that description. If you have any specific questions related to the auto-encoder, I think you should ask them in another post, and I will be glad to help you, if I am able to ;)

one thing I didn't get is why we should go for "denoising" version of autoencoders. That's for when we have corrupted inputs, right? How can it be more helpful here?

@TinaJ Yes, right. I just thought you were looking for something like that. But maybe you're just looking for a "regular" auto-encoder. There are other auto-encoders, such as variational auto-encoder (which might be harder to understand, given that it involves more mathematics). You might want to have a look at that too.


text:
How do I tag the most interesting parts of a video?
This is a follow-up question from my previous question here. I'm new to ML/DL, and one thing I need to do is to use a machine or deep learning video attention model which as the name suggests, can tag which parts of a video is probably more interesting and absorbs more viewer attention.
Do we have an available model to do that? If not, how to do it?


text:
How is an architecture composed of a second model that validates the first one called in machine learning?
I have a mix of two deep models, as follows:
if model A is YES --pass to B--> if model B is YES--> result = YES
if model A is NO ---> result = NO

So basically model B validates if A is saying YES. My models are actually the same, but trained on two different feature sets of same inputs.
What is this mix called in machine learning terminology? I just call them master/slave architecture, or primary/secondary model.

Not in terms of models, but there is a terminology called 'Hierarchical learning', wherein if your model has a task to classify disease, then, If it detects a presence of a disease (disease/ no disease), then it proceeds to further classify a disease(class A/B/C/...). Else it does not proceed.
This technique of hierarchical learning is very common amongst supervised learning tasks.
Now according to your question, you have two models and I assume that they have different tasks and provide a binary outcome(yes/no). Here, you can call it as 'Multitask learning', where the output of task1 is given to task2 for processing.
If task1 detect the presence of disease, then task2 classifies disease into various classes / or segment it / localize it etc.

Thanks. My models are actually the same, but trained on two different feature sets of inputs. So how is this one called?

I am not aware of a specific terminology regarding this. But, if you use the same models just trained on different sets of inputs and you are using both models to infer your final output then that's just plain model assembling. An eg for this is a face recognition model where you train the first model on local features such as eye, nose, mouth, etc, and second model on global features such as overall face texture, size, hair, etc. In the end you would fusion their outputs and average them for prediction. Model averaging is common in ensembling tasks.


text:
Face detection and replacement in photos
I have 2 photos, and my goal is to detect the face in one and place it on the face of the person in the other photo- basically face detection and replacement. It's not deep fakes. It's more of a computer vision-based approach for smoothing the edges and stitching.
How can we achieve that? What are the approaches and techniques to do that? Some tutorials or code or github repos would be very helpful.


text:
Aesthetics analysis with deep learning
I'm trying to score video scenes in terms of aesthetics and cinematography features. Basically, how "interesting" a scene or video frame can be for a viewer. Simpler, how attractive a scene is. My final goal is to tag intervals of video which can be more interesting to viewers. It can be a "temporal attention" model as well.
Do we have an available model or prototype to score cinematographic features of an image or a video? I need a starter tutorial on that. Basically, a ready-to-use prototype/model that I can test as opposed to a paper that I need to implement myself. Paper is fine as long as the code is open-source. I'm new and can't yet write a code given a paper.

Generally we don't just find and link tutorials here. Could you re-phrase the question so that it is more about the problem you face. Any initial thoughts or partial solutions you have would help too, as it helps to pitch the answer correctly for where you are technically. For instance, how familiar are you with CNNs used for image classifying and regression? Have you tried to collect a bunch of images with subjective scores and train a regression model to predict subjective score on new images - or failing that have you looked for such a model?

I'm new to CNN/DL. I couldn't find an available tool. Was hoping to get some useful insights here.

OK, I think the question needs something more to go on that looking for a "starter tutorial" and "get some useful insights". Could you add a little more detail to the question about what you know already from this topic, and what kind of model you are looking for? For instance if someone was to find a mathematical paper discussing the maths of loss functions and complexity of the problem (Google published one or two in this area, amongst others), would it be any use to you? Or are you really looking for some Python code that you can hack? Use [edit] to add details.

Mode ready-to-use prototype/model as opposed to a paper that I need to implement myself. I'm new and can't yet write a code given a paper.

@NeilSlater Btw, do you happen to know the license of using NIMA? Is it OK to use them? There are some open-source implementation of them on Github.

The license of the repo I linked is Apache 2.0, which is a permissive free license plus in theory protects you from patent issues (provided it is licensed correctly by the author). Google quite often publish code under Apache 2.0 so that seems quite normal, and I would not think twice about using the code on a personal project. If you want to be thorough though, you may want to do additional research. If you are using a different repo to the one I linked, then check the license file. Open source does not always mean free to use.

I want to use it for my friend's start-up. There is another repo that implements NIMA also. I was wondering if we should check the repo's license, or NINA'S license, or both?

You should check the repo's license for the repo you want to use, and check whether use of NIMA is encumbered by any patents. The Apache 2 license protects you against copyright and patent claims by the publisher of the repo, so that's a good start. Also, a lot of ML published methods are fine to use in practice, it is a relatively open environment (unlike some areas of research). I would say you are very probably OK to go ahead, but I am not a lawyer - at some point you will want to do legal due dilligence. Personally I would add that to the list of things to check for the startup. Good luck

Aesthetics of images has a strong subjective element and possibility of multiple dimensions depending on purpose of the media. That means:

It is hard to define what we mean by scoring aesthetics.
Given any well-constrained definition, it is then time-consuming to collect relevant data.

However, there is some interest in the machine-learning community, as media quality would be a very useful metric to sort and filter data on (provided the metric is close enough to the end user who wants to select it). As a result, there are data sets, research papers and pre-built models for this.
Media quality training data can be crowdsourced in a variety of ways, including looking at popularity of items on social media, to paying experts to assess large numbers of images. An example of one open dataset compiled by researchers for this purpose is called AVA.
This data might be reduced to image/quality pairs which you can then train a CNN model to predict the quality metric (score out of 10 for example). This might just be a regression, but other more complex loss functions are also considered.
A quick search for existing models brings up Google's NIMA project, which has more than one implementation available as open-source code. NIMA appears to use multiclass classification approach to predict which ratings humans would most likely give the image, and the resulting score is then a weighted average of the predicted scores - the claimed benefit of that seems to be that it better matches how the quality ratings are sourced, and it will better capture split opinions (e.g. half of people think the image is terrible, but half think it is great is a different type of image to one where everyone thinks it is just average).
Here is an implementation of NIMA by Github account "idealo" looks complete with documentation, and ready to use with pre-built scripts.
Just to show this is not a one-off, here's a blog by Andrej Karpathy about using CNNs to rate selfies which includes some introduction to core CNN concepts.

Thanks. Yes I actually found NIMA yesterday, and the pre-trained models are really helping me. Although it's more of a quality assessment (and not attention model), but good enough to start with. It's photo-based (and not video), but still applicable enough.

Your inputs are welcome: https://ai.stackexchange.com/questions/14153/video-engagement-analysis-with-deep-learning


text:
Techniques and semantics in better training of deep learning models
I'm relatively new to Deep Learning, and trying various models and datasets using Keras. I'm starting to love it!
Through-out my experimentations, I have come into some semantic questions that I don't know how they can affect the overall accuracy of my trained model. My target application is fire detection in videos (fire vs non-fire). So I'm trying to get tips and tricks from those well experienced on Deep learning, and here are my semantic questions:

Given that I have to do detection on videos, I've been mostly adding actuall frames of videos to my dataset, and less photos. Does adding photos from Google ever help (as we largen our dataset) or it's actually more considered noises and shall be removed?
I've trained a deep model (ResNet50) as well as a shallow 5-layer model. I realized the ResNet50 model is more sensitive and has a high recall (all fires are definitely detected), but has false positives as well (strong source of lights like sunlight or lamps are identified as fire). While the shallower model is 10x faster, it can miss fires if it is smaller in the image, so it's less sensitive. But also has low false positives. Is it always true? So what are techniques and tips to fix these issues in each of these models?

For instance, the shallow model doesn't see this fire. Shall I think it's not complex enough to work well when the scene has many objects inside?

The sample code I saw resizes photos to 256x256 for training. What's the effect of bigger sizes vs smaller ones say 300x300? Can I expect while bigger sizes increase computation time, they provide higher accuracy?
The sample code also converts photos to grayscale and uses Antialiasing before passing. Does it have good effects? What if I pass the colored version as fire is mostly about colors?
When I see the model is doing bad on certain scenes (say those sun lights or lamps), I take multiple of those frames and add them to my non-fire dataset. Does it have any positive effects and being taken care of? And is it better to add multiple successive frames or just one frame is enough?
My fire dataset has 1800 images and my non-fire dataset has 4500 images. As a rule of thumb, the bigger each class, the better? Of course the non-fire data should be bigger, but we can not add whatever on earth as non-fire so what should be the distribution of the sizes?

Hi Tina. You're asking too many questions on this post. You should try asking one question per post. See https://meta.stackexchange.com/a/39224/287113.

@nbro no they are all semantically related and are essentially one thing. I'm sure if this get a proper answer, it will end up being a very popular post!

If they are essentially one thing, then ask just one question. However, I really think you're asking multiple distinct questions here.

I try to answer the things I know for sure:

One effect of bigger images is the increasing computation time due to more pixels (input to your training)

4.Grayscaling reduces the information, which might decrease training time, but also model performance (accuracy, precision, recall). What I have seen is that grayscaling is used in for example face detection where structural information (shapes) is important and colors can be regarded as secondary. For your example you have to determine whether such structural differences between positives and negatives exist and if color is a valuable information.

If possible, I would somehow alter these copies by clipping the objects (sun lights, lamps) and rotate, scale, make them transparent etc.
In the end your training data should be representative of the data it should generalize to. If you would for example take my user icon as an additional non fire example, this wouldn't help your cause.

For 5, you mean keep multiple frames and plus, multiple each by keeping altered copies?


text:
Video summarization similar to Summe's TextRank
We have the popular TextRank API which given a text, ranks keywords and can apply summarization given a predefined text length.
I am wondering if there is a similar tool for video summarization. Maybe a library, a deep model or ML-based tool that given a video file and a length, it ranks frames, or video scenes/shots. I'd like to generate a short summary of a video with visual features.

as in video -> text or frame ranking?

Frames, or Shots of the video.

From "Deep learning-based video summarization — A detailed exploration" by Surya Remanan:
Video summarization can be considered as the process of distilling a raw video into a more compact form without losing much information. In a general video summarization system, image features of video frames are extracted, and then the most representative frames are selected through analyzing the visual variations among visual features. This is done either by taking a holistic view of the entire video or by identifying the local differentiation among the adjacent frames. Most of those attempts rely on global features such as colour, texture, motion information, etc. Clustering techniques are also used for summarization. Video summarization can be categorized into two forms:

Static video summarization (keyframing) and
Dynamic video summarization (video skimming)

Static video summaries are composed of a set of keyframes extracted from the original video, while dynamic video summaries are composed of a set of shots and are produced taking into account the similarity or domain-specific relationships among all video shots.
Following is an attention-based video summarization model - PyTorch implementation of the ACCV 2018-AIU2018 paper Video Summarization with Attention
There is a video summarisation focused models using reinforcement learning -  Unsupervised video summarization with deep reinforcement learning (Theano)
There is an LSTM - GAN based approach to video summarization - video summarization lstm-gan pytorch implementation
Microsoft Bing Search has come up with a video summarization technique using thumbnails. Intelligent Search: Video summarization using machine learning

Most of the text of your answer was taken exactly from: https://heartbeat.fritz.ai/deep-learning-based-video-summarization-a-detailed-exploration-8b1a25946404 Maybe you should consider citing the source..

Edit proposed to solve the issue discovered by Enrique. See https://meta.stackexchange.com/questions/160071/what-to-do-when-plagiarism-is-discovered recommendations.


text:
Use AI/Computer Vision to detect scene changes
I'm trying to use AI and computer vision techniques to identify scene changes for a camera. Something like this:

What are some approaches to do this? Any ideas?
The scene is static. Somewhere I saw a user trains the app with multiple images of normal scenes, and the app monitors the amount of pixel change from the trained images. And it issues an alarm when the amount of pixel change exceeds a threshold for a specified time period. But it should be more complex than that. A human may walk around or shadows and sunlight might affect the scene, so it won't be a scene change and no anomaly.

If you have only such static scene and want to know if a static object where removed, you probably dont dont need deep learning. Just do background subtraction.

It is static; but remember we have shades, shadows and humans passing. Does it work? Actually a simpler approach would be better!

What they are suggesting is literally do a difference on the two images. The pixels will be different and you will know that something has changed.

crosspost: https://forum.opencv.org/t/door-blockage-detection-using-opencv/13927


text:
Which neural network is appropriate for measuring object dimensions from stereo images?
I have stereo pairs (left, right) images of concrete cracks. I want to measure the length of the crack from those image pairs. Which neural network is appropriate for measuring object dimensions from stereo images?
Note: I am insisted to use the NN-based technique only.

Hi and welcome to this site! What do you mean by "images of a site"? Which site? Maybe you can provide an example of a pair of images with the object whose size you want to measure. I think that would clarify your problem.

Thanks for the intimation. I have edited my description.

Is the image taken from a constant distance?
If yes, you'd need to scale the images to the same dimensions first of all. For few images say 100-500 images (more the better) you'd need to label the dataset by proper scaling.
Once labeled, use it to train a CNN (Although best would be training a ResNet). Once trained with decent accuracy, test it for the rest of your dataset.
I did something similar for one of my projects, check it out if you want to here.

Thank you for your information and reference. Will check it.

If you have stero pairs, and you can identify the objects in the scene, you do not need a neural network, you can just use triangulation.
If you need to identify which objects in the scene are the same, you have an image segmentation problem. Depending on your problem and the amount of data you have access to, you may be able to use simple techniques like clustering-based segmentation, or you may be able to use NN-based techniques, like Mask R-CNN.

I am supposed to work with NN only. My application is measuring the crack length from the underwater concrete images. I am aware of doing semantic segmentation using Mask R-CNN. But I don't know how to use it to measure the length. Could you please provide any suggestions?

@ovezn If you have stero images of the same object, taken with a stero camera, you can use triangulation to determine depth (i.e. the distance of the object from the camera). As soon as you know that, you can determine the length of an object in the picture. So the only thing you really need to do here is identify the object in the picture that is a "crack". That last part is an image segmentation task. Although you could try to solve the rest of the task with a neural network too, that's likely to be both harder, and less effective, than doing it properly by exploiting the depth.


text:
How to count pixels in a object mask which is segmented using Mask R-CNN?
I have segmented concrete cracks from concrete structure images using Mask R-CNN. Now I need to measure the length of the segmented masked crack.
Will the pixel counting method work? Can anyone help?
Note: The images are taken at the constant distance from the object.


text:
Does MMD-VAE solve the problem of blurred images of vanilla VAEs?
I understand that with vanilla VAEs, there are a few reasons justifying the production of blurred out images. The InfoVAE paper describes the case when the decoder is flexible enough to ignore the latent attributes and generate an averaged out image that best reduces the reconstruction loss. Thus the blurred image.
How much of the problem of blurring is really mitigated by the MMD formulation in practical experiments? If someone has experience working with MMD-VAEs, I'd like to know their opinion on what the reconstruction quality of MMD-VAEs is really like.
Also, does the replacement of the MSE reconstruction loss metric by other perceptual similarity metrics improve generated image quality?

[Answering my own question after 5 months of studying VAE models]
The point of the MMD-VAE or InfoVAE is not exactly to emphasise on the visual quality of generated samples. It is to preserve greater amount of information through the encoding process. The MMD formulation stems from introducing a mutual coefficient factor into the Evidence Lower BOund (ELBO) loss of VAEs. Refer to the paper appendices for full derivation. This formulation improves information content in latent space and provides for more accurate approximation of the true posterior - these results have also been empirically proven in the paper.
However, the InfoVAE uses pixel-wise or element-wise reconstruction loss. An element-wise reconstruction loss is likely to lead to some extent of blurriness inrespective of the prior loss term. On Github, several developers have implemented the InfoVAE model and shown their results. Here is a link to one such implementation whose results I could personally verify.
From my own experimentations, I can say that even though InfoVAE may give better reconstructions for some data, there is still considerable blurriness.
Perceptual similarity metrics may be learned or computed as a static function of the input image. With a learned perceptual loss, VAEs can produce much sharper images. PixelVAE and VAEGAN are well-known models with such implementations. For a static function of the image itself, reconstruction quality will depend on the nature of that function and such a model may not be very useful for all kinds of datasets. Using measures like SSIM, FSIM, we may still end up getting blurred images.


text:
How are non-linear surfaces formed in the training of a neural network?
Desperate trying to understand something for couple of weeks. All those questions are actually one big question.Please help me. Time-codes and screens in my question refer to this great(IMHO) 3d explanation:
https://www.youtube.com/watch?v=UojVVG4PAG0&list=PLVZqlMpoM6kaJX_2lLKjEhWI0NlqHfqzp&index=2
....
Here is the case: Say I have 2 inputs (lets call them X1 and X2) into my ANN. Say X1= persons age and X2=years of education.
1) First question: do I plug those numbers as is or normalize them 0-1 as a "preprocessing"?
2) As I have 2 weights and 1 bias, actually I am going to plug my inputs to X1*W1+X2*W2=output formula.  This is 2d plane in a 3d space if I am not mistaken(time-code 5:31):

Thus when I plug in my variables, like in regression I will get on a Z axis my output.  So the second question is: am I right up to here?
-----------------From here come  real important couple of  questions.
3) My output (before I plug it into the activation function) is just a simple number, IT IS NOT A PLANE and NOT A SURFACE, but a simple scalar, without any sigh on it coming from 2d surface in a 3d space(though it does come from there). Thus, when I plug this number (which was Z value in a previous step) into the activation function (say sigmoid) my number enters there in to the X axis,  and we get as an output some Y value. As I understand  this operation was totally 2d operation, is was 2d sigmoid and not some kind of 3dsigmoidal surface.
So here is the question: If I am right, why do we see in this movie (and couple of other places) such an explanation?
(time-code 12:55):
4)Now lets say that I was right in the previous step and as an output from the activation function I do get a simple number not a 2d surface and not a 3d one. I just have some number like I had in the very beginning of the ANN as an input (age, education etc). If i want to add another layer of neurons, this very number enters there  as is not telling any one the "secret" that it was created by some kind of sigmoid. In this next layer this number is about to take similar transformations as it happened to age and education in a previous layer, it is going to be Xn in just the same scenario: sigmoid(XnWn+XmWm=output) and in the end we will get once again just a number. If I am right, why in the movie they say (time-code 14:50 ) that when we add together two activation functions we get something unlinear. They show result of such "addition" first as 2d (time-code 14:50 and 14:58).

So, Here comes my question:  how come that they "add" two activation functions, if to the second activation function reaches just a simple number as said above he is not telling any one the "secret" that it was created by some kind of sigmoid.
5) And then again, they show this addition of 3d surfaces (time-code 19:39 )
 How it is possible? I mean again there should not happen any addition of surfaces, because no surface passes to next step but a number. What do I miss?

Hi and welcome to the community. It's important to understand these basic concepts very clearly.
You have to first understand the basic unit of a neural network, a single node/neuron/perceptron. Let us forget all about Neural Networks for a bit, and talk about something far simpler.
Linear Regression

In the above figure, we clearly have one independent variable on the x-axis, and one dependent variable on the y-axis. The red line has an intercept of zero, and let's say a slope of 0.5. Therefore,
$$ y = 0.5x + 0 $$
This, right here, is a single perceptron. You take a value of x, lets say 8, pass it through the the node, and get a value as output, 4. Simple!
But what is the model in this case? Is it the output? No. Its the set [0.5, 0] that represents the red line above. The outputs are simply points on that line.
A neural network model is always a set of values - a matrix or a tensor, if you will.
The plots in your question, do not represent outputs. They represent the models. But now that you've possibly understood what a linear model with one indpendent variable looks like, I hope you can appreciate that having 2 independent variables will give us a plane in 3-D space. This is called multiple regression.

This forms the first layer of a neural network with linear activation functions. Assuming $ x_{i} $ and $ x_{j} $ as the two independent variables, the first layer computes
$$ y_{1} = w_{1}x_{i} + w_{2}x_{j} + b_{1} $$
Note that while $ y_{1} $ is the output of the first layer, the set $ [w_{1}, w_{2}, b_{1}] $ is the model of the first layer and can be plotted as a plane in 3D space.
The second layer, again a linear layer, computes
$$ y_{2} = w_{3}y_{1} + b_{2} $$
Substitute $ y_{1} $ in above and what do you get? Another linear model!
$$ y_{2} = w_{3}(w_{1}x_{i} + w_{2}x_{j} + b_{1}) + b_{2} $$
Adding layers to a neural network is only compounding of functions.
Compounding linear functions on linear functions result in linear functions.
Well, then, what was the point of adding a layer? Seems useless, right?
Yes, adding linear layers to a neural network is absolutely useless. But what happens if the activation functions of each perceptron, each layer was not linear? For example the sigmoid or the most widely used today, ReLU.
Compounding non-linear functions on non-linear functions can increase non-linearity.
The ReLU looks like this
$$ y = max(0, x) $$

This is definitely non-linear but not as non-linear as let's say the sine wave. But can we approximate the sine wave by somehow "compounding" multiple, say $ N $ ReLUs?
$$ \sin(x) \approx a + \sum_{N}b*max(0, c + dx)$$
And here the variables $ a, b,c, d $ are the trainable "weights" in neural network terminology.

If you remember the structure of the perceptron, the first operation is often denoted as a summation over all the inputs. This is how non-linearity is approximated in Neural Networks. Now one may ask: So, summing over non-linear functions can approximate any function, right? So a single hidden layer between input layer and output layer (one that sums over all the outputs of the hidden layer units) should be enough? Why do we often see neural network architectures with so many hidden layers? This is one of the most important yet often overlooked aspect of neural networks and deep-learning.
To quote, Dr. Ian J Goodfellow, one of the brightest minds in AI,

A feedforward network with a single (hidden) layer is sufficient to represent any function, but the layer may be infeasibly large and may fail to learn and generalize correctly.

So, what is the ideal number of hidden layers? There's no magic number! ;-)
For more mathematical rigor on how neural networks approximate non-linear functions, one should learn about the Universal Approximation Theorem. Beginners should check this out.
But why should we care for increased non-linearity? For that I'd direct you to this.
Note that all of the above discussion is with respect to regression. For classification, the non-linear surface learned is regarded as a decision boundary and points above and below the surface are classified into different classes. However, an alternative, and arguably better, way to look at this is that given a dataset that is not linearly seperable, a neural network first transforms the input dataset into a linearly seperable form and then uses a linear decision boundary on it. For more on this, definitely check out Christopher Olah's amazing blog.
Finally, yes all independent variables must be normalized before training a neural network. This is to equalize the scale of different variables. More info here.

Wow, thank so much to all who answered me, I think it is clear right now. Allways love to say in my own words what I understood, so here are 3 simple yes/noquestions to make sure (watch pic attached as above as my own answer to myself). Thank you very much once again. Igor

The output of any node is simply a scalar number. For a given input you get a specific scalar output. What is being shown is the surfaces that get generated as you VARY x1 and x2 over their input range.
To answer your first question it is always best to scale your inputs.


text:
How can I evaluate a reinforcement learning algorithm over an entire problem space?
I am working on implementing an RL agent and I want to demonstrate its effectiveness over a bounded problem space. The setting is essentially a queueing network and so it can be represented as a graph. I want to consider the agent's performance over all graphs up to order $n$ and with average degree from $0$ (edgeless) to $n-1$ (fully connected).
I have looked into generating random graphs using the Erdős–Rényi model, for example. My thought is that I could show the average performance of my agent for different settings of number of nodes and edge probability (under this particular graph generation model).
Are there any established techniques that are along the lines of this approach?

It's not clear to me what you want to represent as a graph (and how exactly do you want to do it? i.e. what are the nodes and edges of this graph?), probably because I don't know what you mean by "queueing network". Moreover, what do you mean by "bounded problem space"? What is bounded here? Finally, I don't understand why you want to evaluate the agent's performance over all graphs? What graphs are you talking about?

Thanks for the link. But I think it would be helpful for those not familiar with queuing networks if you described more explicitly your state space, the action space (remember that, in RL, you typically assume that your problem/environment can be modelled as a Markov decision process? That's why I am asking this info), what RL algorithm you are using, and why your problem is bounded, and why this information is important.

I think the root of my question is independent of my particular MDP formulation. Say we forget the queueing network example and consider a grid world problem (which is probably more familiar to most). I can define a specific grid world instance, with some positive reward positions and some negative, and show that my agent does well most of the time when faced with this specific instance. What I am interested in is showing that my agent does well on many different grid world instances up to a certain grid size, and with various densities of positive and negative reward states.

I know someone that is working on a very similar problem. Unfortunately, I can't share with you the details. However, to answer your question "Are there many approaches trying to do a similar thing?", I would say "no", so you may want to investigate your own approaches or try something new.


text:
Multi label Classification using Keras
I am trying to build a Multi label classification model, having dataset with different input numerical values and specific label...
Eg:
Value Label
35   X
35.8 X
29   Y
29.8 Y
39   AA
41   CB
So depending on input numerical value the model should specify its label....please note that the input values won't necessarily follow exact dataset values....eg dataset has 35 and 34.8 as input values with X as label. So if model has 35.4 as input label, the X should be output label. Bottom line is that the output label is based on range of input values instead of fixed one..
Can anyone help me with quick solution (example Jupyter notebook will be highly appreciated)

For a simple multi layer perceptron, you can refer to here:
https://www.kaggle.com/fchollet/simple-deep-mlp-with-keras
This is a great resource for kerad multi input label classification. Also, here is a few reminders for implementing such classification model.
One hot encoding
In the sample data you provided, it seems like you are using raw numbers as input. This will create unnecessary complications for the model. A better approach will be to encode them into a vector with 0 in all except one index with 1. The index will be the numerical value you are encoding. For example, 1 will be 01000000... Till end of your range of input, and 2 will be 001000 and so on. If you have decimal values, then this approach isn't for you. However you should still scale down your input to something smaller like 0-1.
output encoding
The output seems to be text, which cannot be done and also complicates the problem. Instead you can also use one hot encoding for the output. For example, let A be 0, B be 1, C be 2... AA be 27.... Until your list ends. And then use one hot encoding to encode them to vector of 0 and 1.
Hope I can help you.


text:
Is it possible to reverse engineer out the loss based on weights update when data is unknown?
Assume the gradient updates (both $W_t$ and $W_{t+1}$) and learning rate are known while data $X$ is unknown, is it possible to deduce the loss $L$ used in backprop algorithm that gave rise to the gradient update $W_{t+1} - W_{t}$? If not, is it possible to verify if a given loss is the one we are looking for (in other words is the loss that gave rise to a known gradient update unique, assume we know the model architecture)?

This depends on your definition of Loss $L$, $L$ such as MSE is easily calculable according to its formula after each forward pass and its error terms for each output unit are then used to backprop.

First, there is no way you could recover the exact loss. At best you could recover the loss up to a constant factor, because the gradient is only giving information on the slope on the loss and not the actual loss values.
If we make assumptions like a standard model architecture, and we have access to the model architecture in addition to the weight values, then it might be possible to recover the loss up to a constant factor. Assuming the (scalar) loss depends only on the output layer, and assuming the weights are updated with vanilla SGD, first we have an eqn like
\begin{align*}
\frac{1}{\alpha}(W_{t+1} - W_t) = \dfrac{\partial f}{\partial x_n}\Big(\dfrac{\partial x_n}{\partial W_t} + \dfrac{\partial x_n}{\partial x_{n-1}}\dfrac{\partial x_{n-1}}{\partial W_t} + \ldots \Big)
\end{align*}
where $\alpha$ is the learning rate, $f$ is the loss function, $x_i$ are the units of the $i$-th layer ($x_n$ is output, $x_0$ is input). the LHS is what you know the gradient was and the RHS is the definition of the gradient (based on backprop). In the RHS, the unknowns are the partial derivatives $\frac{\partial f}{\partial x_n}$, which has as many unknowns as dimension of the output layer. This is an over-determined system, because there are only $\text{dim}(x_n)$ unknowns and $\dim(W)$ equations. Normally this would then have no solution, but in this case, we know there actually are some loss partial derivatives $\partial f / \partial x_n$ which should satisfy this.
But this doesn't give you the actual function f. You just get the partial derivatives at $x_n$. Then if you wanted to try to recover $f$ (again, only up to a constant factor), you would need a way to actually evaluate various different $x_n$. Then you can "recover" $f$ (up to a constant factor) by integrating $\partial f / \partial x_n$ over all possible values of $x_n$.


text:
Understanding the results of "Visualizing and Understanding Convolutional Networks"
I am trying to understand the results of the paper Visualizing and Understanding Convolutional Networks, in particular the following image:

What are these 3x3 blocks and their 9 cells representing?
From my understanding, each 3x3 block of the i-th layer corresponds to a randomly chosen feature map in that layer (e.g. for the layer-1 they randomly chose 9 feature maps, for layer-2 16 feature maps etc). On the left part (grayish images), the j-th 3x3 block shows 9 visualizations obtained by mapping the top-9 activations (single values) of that particular feature map to the "pixel space" (using a deconvolutional network). On the right part, the j-th block shows the 9 patches of input images, corresponding to the top-9 activations (e.g. in the first layer and i-th feature map, the j-th image patch is the local region of input image which is seen by the j-th neuron of that feature map). Is my understanding correct?
However, it's not entirely clear to me how the top-9 activations are chosen. It seems that for each layer and each feature-map, an activation is picked for a different input image (that's why we see e.g. different persons in layer-3, row-1, col-1, and different cars in layer-3, row-2, col-2). So within each block, the top-9 activations are obtained from 9 different images (but images of the same class) of the entire dataset (but in principle it could be that more than one activations are coming from the same image).


text:
Could AI kill the joy of competitive sports and games?
Lee Sedol, former world champion, and legendary Go player today announced his retirement with the quote "Even if I become the No. 1, there is an entity that cannot be defeated".
Is it possible that AIs could kill the joy of competitive games(Go, chess, Dota 2, etc.) or (thinking more futuristic with humanoid AIs) in sports?
What happens if AIs gets better than us at painting and making music. Will we still appreciate it in the same way we do now?

Does the fact that men are better at running 100m sprint race killed the joy of competitive sports (running) in women?

I have worried this fact a few times ago :/

Unlikely!
Chess has been "solved" by AI much longer than GO (chess engines even before AI are way too strong for human players) and still people are playing and competing.
Simply put competition and sports live from the human element. Humans competing against each other will still create the same joy for most people regardless of the fact that all involved players might lose against a computer.
Some select individuals on the highest level might be put off by the new reality but it won't be the end of competition.
No human is faster than a car and yet we still celebrate running competitions.
Indeed I think long-term we will gain entertainment by watching different AIs and models compete against each other in chess or Go.

authors: Кристина Митрович


text:
What can model everything?
I've been thinking about what "mathematical model" can be used to model every possible thing (including itself).
Examples: a simple neuron network models a function but doesn't model an algorithm. A list of instructions models an algorithm but doesn't model relations between elements...
You might be thinking "maybe there is nothing that can model everything" but in reality "language" does model everything including itself. The issue is that it's not an organized model and it's not clear how to create it from scratch (e.g. if you will send it to aliens that don't have any common knowledge to start with).
So what is some possible formalization of a mathematical model that models every possible thought that can be communicated?
Edit 1:
The structure formalization I'm looking for has to have a few necessary properties:

Hierarchical: the representation of ideas should rely on other ideas. (E.g. an programming function is a set of programming functions, the concept "bottle of water" is sum of two concepts "water" and a "bottle"...)
Uniqueness of elements: When an idea uses in its definition another idea, it must refer to one specific idea, not recreate it each time. For example, when you think of a digit "9" and the digit "8", you notice that both have a small circle at the top, you don't recreate a new concept "circle" every time, instead, you use a fixed concept "circle" for everything. By contrast, a neural network might recreate the same branch for different inputs. So two representations of concepts must be different iff they have a difference.)

Hi and welcome to this community! You should precisely define "everything", "thought" and "X models Y". Also, what do you mean by "in reality "language" does model everything including itself"

@nbro Your questions are helpful because I don't know what to explain more. "Everything" means thoughts, concepts, ideas and basically everything that can be expressed with language. For example, you can't explain what "the color red" is, so it doesn't count as a thought for my question. But here are examples of things I would like the same model to be able to represent: two objects have similar color or not (a relation), how to brush teeth (an algorithm), what can be considered a "3" (a classification)... Notice how I used language to make you think of those examples.

Category Theory seems promising.  There's a great free textbook Seven Sketches in Compositionality.  Technically, anything can be a set, but Set Theory is mostly about cardinality and paradoxes, where Category Theory is more about functions and their relations, and more suitable for engineering.

@RationalFragile I still have no idea of what you're looking for. What do you mean by "X models Y"? The language is just a means of communication in this case.

@DukeZhou I don't know almost anything about category theory, but, AFAIK, it is basically an abstract field. The only application I remember is related to functional programming languages (such as Haskell).

@nbro Applied Category Theory wiki.  I'm just starting to dip my toe in, but it seems to have the potential to be applied to anything, including the humanities.  (Borges wrote about the mathematical underpinnings of narrative, as an example.  Been a while since I read his writing on that, but I recall it was rooted in set theory.)  AGI would surely require a system for modeling even non-scientific abstraction, such as metaphors and ideas. Also following some mathematicians applying it to game theory.

@nbro I'm not looking for something necessarily "applied". I am looking for an abstract way to represent anything. The point is, I want to design a system that can learn anything but if I can't even represent anything, it wouldn't be possible. "X models Y" means that if I never met you and I don't even know what language you speak, I can send you "X" when I want to communicate to you the idea of "Y". For example, I can send you a trained neural network to communicate to you a function.

The only thing that comes to my mind now is AIXI. I still think that your question cannot be answered unambiguously. Maybe someone else will be able to answer it or maybe category theory is something you're looking for.

It is unclear to me how Category theory or AIXI represent things in a universal way. I have updated the question to mention a few necessary properties of the architecture I'm looking for. To clarify, what I look for is a "data structure" in a sense, but the data itself can represent anything. I can make one that will handle one type of things well, e.g. "action = action then action | action or action". This can be used to represent any complicated action but cannot for example represent a function (like a neural network does). So my goal is to unify all these hierarchies if that makes sense.

Doesn't Gödel's incompleteness theorem prove that there is no formal system that can even completely describe itself?

@GeorgeWhite I'm not quite sure about that. There is no truth value to the "ideas" in the sought after structure. (Being false or true is in itself an idea.) Besides, I am assuming that there will be a finite number of fixed elementary "ideas" such as "neuron is firing or not" but beside those, there will be an infinite number of combinations that each get to be called an "idea". Just like in language, there are no truth value to words but you can combine them to create any infinitely complex book. (You have to rely on the "elementary ideas" while learning the language at first...)