machine-learning

Keras' fit_generator() for binary classification predictions always 50%

梦想的初衷 提交于 2021-02-10 17:29:29
问题 I have set up a model to train on classifying whether an image is a certain video game or not. I pre-scaled my images into 250x250 pixels and have them separated into two folders (the two binary classes) labelled 0 and 1 . The amount of both classes are within ~100 of each other and I have around 3500 images in total. Here are photos of the training process, the model set up and some predictions: https://imgur.com/a/CN1b6LV train_datagen = ImageDataGenerator( rescale=1. / 255, shear_range=0,

Splitting training data with equal number rows for each classes

自古美人都是妖i 提交于 2021-02-10 15:51:29
问题 I have a very large dataset of about 314554097 rows and 3 columns. The third column is the class. The dataset has two class 0 and 1. I need split the data into test and training data. To split the data I can use from sklearn.cross_validation import train_test_split . X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.75, random_state = 0) But, The dataset contains about 99 percent of class 0 and only 1 percent of class 1. In the training dataset, I need an equal number of

Why is my CPU doing matrix operations faster than GPU instead?

江枫思渺然 提交于 2021-02-10 15:38:32
问题 When I tried to verify that the GPU does matrix operations over the CPU, I got unexpected results.CPU performs better than GPU according to my experience result, it makes me confused. I used cpu and gpu to do matrix multiplication respectively.Programming environment is MXNet and cuda-10.1. with gpu: import mxnet as mx from mxnet import nd x = nd.random.normal(shape=(100000,100000),ctx=mx.gpu()) y = nd.random.normal(shape=(100000,100000),ctx=mx.gpu()) %timeit nd.dot(x,y) 50.8 µs ± 1.76 µs per

How to change the backend of Keras to Theano?

半腔热情 提交于 2021-02-10 15:28:09
问题 I installed keras. When I import keras, it says tensorflow not installed. I tried changing the backend in keras.json file to theano. But this doesn't help as it still says no module named tensorflow. Please help me fix this. 回答1: Did you try this? you will find the Keras configuration file at: $HOME/.keras/keras.json The default configuration file looks like this: { "image_data_format": "channels_last", "epsilon": 1e-07, "floatx": "float32", "backend": "tensorflow" } Simply change the field

Binary classification with softmax activation always outputs 1

核能气质少年 提交于 2021-02-10 15:16:58
问题 Sorry for the quality of the question but a beginner here , I was just trying my luck with titanic dataset, but it always predicts that the passenger died. I try to explain code below: import matplotlib.pyplot as plt import numpy as np import pandas as pd import seaborn as sns import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers from tensorflow.keras import losses from tensorflow.keras.layers.experimental import preprocessing import os Load dataset dataset

Binary classification with softmax activation always outputs 1

回眸只為那壹抹淺笑 提交于 2021-02-10 15:14:50
问题 Sorry for the quality of the question but a beginner here , I was just trying my luck with titanic dataset, but it always predicts that the passenger died. I try to explain code below: import matplotlib.pyplot as plt import numpy as np import pandas as pd import seaborn as sns import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers from tensorflow.keras import losses from tensorflow.keras.layers.experimental import preprocessing import os Load dataset dataset

How to handle missing values (NaN) in categorical data when using scikit-learn OneHotEncoder?

笑着哭i 提交于 2021-02-10 15:10:07
问题 I have recently started learning python to develop a predictive model for a research project using machine learning methods. I have a large dataset comprised of both numerical and categorical data. The dataset has lots of missing values. I am currently trying to encode the categorical features using OneHotEncoder. When I read about OneHotEncoder, my understanding was that for a missing value (NaN), OneHotEncoder would assign 0s to all the feature's categories, as such: 0 Male 1 Female 2 NaN

Error when checking input: expected embedding_1_input to have shape (4,) but got array with shape (1,)

拟墨画扇 提交于 2021-02-10 14:43:51
问题 I use pretrained embedding vectors for my keras model. Before I did it everything worked and now I get this error: ValueError: Error when checking input: expected embedding_1_input to have shape (4,) but got array with shape (1,) Maybe somebody can help me, what I do wrong here. I am not sure if I did correct model.fit and model.evaluate. Maybe there is a problem? import csv import numpy as np np.random.seed(42) from keras.models import Sequential, Model from keras.layers import * from random

Error when checking input: expected embedding_1_input to have shape (4,) but got array with shape (1,)

混江龙づ霸主 提交于 2021-02-10 14:40:36
问题 I use pretrained embedding vectors for my keras model. Before I did it everything worked and now I get this error: ValueError: Error when checking input: expected embedding_1_input to have shape (4,) but got array with shape (1,) Maybe somebody can help me, what I do wrong here. I am not sure if I did correct model.fit and model.evaluate. Maybe there is a problem? import csv import numpy as np np.random.seed(42) from keras.models import Sequential, Model from keras.layers import * from random

Shape error when passed custom LSTM

六月ゝ 毕业季﹏ 提交于 2021-02-10 14:21:01
问题 I have been trying to custom a LSTM layer for further improvement. But an error which seems like normal raised at pooling layer after my custom LSTM. My environment is: win 10 keras 2.2.0 python 3.6 Traceback (most recent call last): File "E:/PycharmProjects/dialogResearch/dialog/classifier.py", line 60, in model = build_model(word_dict, args.max_len, args.max_sents, args.embedding_dim) File "E:\PycharmProjects\dialogResearch\dialog\model\keras_himodel.py", line 177, in build_model l_dense =