yu4u / age-gender-estimation Goto Github PK
View Code? Open in Web Editor NEWKeras implementation of a CNN network for age and gender estimation
License: MIT License
Keras implementation of a CNN network for age and gender estimation
License: MIT License
When I tried to run "create_db.py", after the progress bar reached 100%, my computer was frozen. After a while, the command line output a word "killed". Since a file called imdb_db.mat was found in the directory "data",I tried to continue the training process, but the error "IOError: could not read bytes" appeared.
I checked the "imdb.mat" in the directory "imdb_crop" with Octave(I don't have MATLAB), I found that I can't be loaded into Octave. The error "warning: load: can not read non-ASCII portions of UTF characters; replacing unreadable characters with'?'" appeared when I tried to load the "imdb.mat". I did the same to "imdb_db.mat",the error " error: load: reading matrix data for 'image'
error: load: trouble reading binary file '/home/mt/Downloads/age-gender-estimation-master/data/imdb_db.mat'" appeared. Only gender,img_size,min_score was loaded.
Is the file "imdb.mat" corrupted? Or I used the file wrongly? I am looking forward to your reply. Your help will be greatly appreciated.
First all, thank you for this program.
If I wanted to check for the accuracy for a particular age range, how would I do it? For example, if I wanted to check if the age range was between 20-30 and everyone that lies in that age range is a hit and outside of it is a miss, what do you think would be the best way to approach this? I am mostly concerned about the accuracy which I believe is dense_2_acc
Thank you
Hi,
I unzipped the imdb_0.tar in the data folder I created.
After I run python create_db.py --output data/imdb_db.mat --db imdb --img_size 64
and get the following error:
Traceback (most recent call last):
File "create_db.py", line 66, in
main()
File "create_db.py", line 36, in main
full_path, dob, gender, photo_taken, face_score, second_face_score, age = get_meta(mat_path, db)
File "C:\Users\xxx\Desktop\Eye_Tracking\age-gender-estimation-master\utils.py", line 17, in get_meta
meta = loadmat(mat_path)
File "C:\Users\xxxl\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\io\matlab\mio.py", line 141, in loadmat
MR, file_opened = mat_reader_factory(file_name, appendmat, **kwargs)
File "C:\Users\xxx\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\io\matlab\mio.py", line 64, in mat_reader_factory
byte_stream, file_opened = _open_file(file_name, appendmat)
TypeError: 'NoneType' object is not iterable
Can you help me? I think is a dataset problem
In the demo file, I can't see any mean subtraction from the input images on the webcam. Is that correct?
I tried to speed up the serving program and found three solutions :
-1 Replace dlib.get_frontal_face_detector
with Face Detection from Yeephycho's SSD Mobilenet (https://github.com/yeephycho/tensorflow-face-detection)
-2 Using tensorflow.keras rather than Keras for age and gender classification.
-3 Using imutils.video.WebcamVideoStream
in order to have a Thread dedicated to VideoCapture (https://www.pyimagesearch.com/2015/12/21/increasing-webcam-fps-with-python-and-opencv/).
I didn't benchmark my updates but (1) allows me to jump from 5fps to 25fps (with a 1080Ti), (2) jump from 260ms by age/gender classification to 220ms (PC with no GPU) and (3) ... I don't know but it looks better !
If someone is interested, I can share my updates.
Hi yu4u,
I want to train the network with 128 image size. (40k images)
However, the lost reduce stop at 24 (at 20 epochs) and then it doesn't decrease anymore. I've tried with adam, sgd, rmsprop. But the results are all the same.
Do you have any tips for training the network from scratch? Or is there any pretrained weights for 128 image size?
Thanks for the age-gender-estimation code!
Your pretrained model works great!
However, when trying to reproduce your results by training myself with the same training data, I face the problem that the neural net only learns to predict the same class for each image. Overfitting on a small training data set (only 1-2 images per class) works, but beyond that I could not generalize. I tried various parameter ranges including the default values for learning rate, dropout, depth and width and so on, but it didn't help.
Any ideas?
I am new in python. I training the data from UTFFace, but it too very long time. Any method that can train the data in short time? Thank you.
Versions:
Python 3.6.2 :: Anaconda custom (64-bit)
$ python -c "import cv2; print(cv2.version);" => 3.3.0
Keras==2.0.6
dlib==19.7.0
scikit-image==0.13.0
scikit-learn==0.19.0
scipy==0.19.1
numpy==1.13.1
pandas==0.20.3
h5py==2.7.0
tables==3.4.2
When I run demo.py, I get this error:
Traceback (most recent call last):
File "demo.py", line 99, in
main()
File "demo.py", line 80, in main
results = model.predict(faces)
File "C:\Anaconda3\lib\site-packages\keras\engine\training.py", line 1499, in predict
check_batch_axis=False)
File "C:\Anaconda3\lib\site-packages\keras\engine\training.py", line 140, in _standardize_input_data
str(array.shape))
ValueError: Error when checking : expected input_1 to have shape (None, 3, 64, 64) but got array with shape (1, 64, 64, 3)
Any ideas?
I ran the demo.py on my computer already.
It is perfect but somehow it can not distinguish gender correctly.
I am wondering it probably was trained by IMDB-wiki and does not perform well on Asian's face.
So I decide to train the model with UTKFace which will be linked right here: https://susanqq.github.io/UTKFace/
Is my assumption right?
Could you give me some advice about how to train the model instead of IMDB-wiki?
Hello, I found strange things on dataset maximum age is 2014 and minimum age is -31.
I tried using your code in
https://github.com/yu4u/age-gender-estimation/blob/master/create_db.py in line 34 and
I add several code
mat_path = "../imdb.mat"
db = "imdb"
full_path, dob, gender, photo_taken, face_score, second_face_score, age\
= get_meta(mat_path, db)
path_list = [str(item[0]) for item in full_path.tolist()]
max_age = np.max(age) #result 2014
max_age_idx = np.argmax(age) #result 181492
path_photo = path_list[max_age_idx] #result '64/nm1002664_rm1109196544_0-7-31_2015.jpg'
and link dataset I download is https://data.vision.ee.ethz.ch/cvl/rrothe/imdb-wiki/static/imdb_crop.tar
hello, interested in your code, but when I run demo.py, it shows error:
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /io/opencv/modules/imgproc/src/color.cpp, line 9716
Traceback (most recent call last):
File "demo.py", line 70, in <module>
main()
File "demo.py", line 33, in main
input_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
cv2.error: /io/opencv/modules/imgproc/src/color.cpp:9716: error: (-215) scn == 3 || scn == 4 in function cvtColor
How to fix it? My cv2 in python is 3.2.0. Python is 2.7
thank you very much~~
After training, I have got series of hdf5 file. How do I combine files hdf5 files after training?
from wide_resnet import WideResNet
ModuleNotFoundError: No module named 'wide_resnet'
How do I train only the age?
Hi
I'm trying to train the model on my own smaller dataset. When I predict gender, I get an array full of only [1,0], [1,0], [1,0],...... instead of getting different probabilities.
Why does this happen? What is the minimum size of dataset I can use?
Thanks
Hello yu4u,when I run 'python3 train.py --input data/imdb_db.mat' ,
(ubuntu14.04, python3.5,cuda8.0,cudnn5.0,tensorflow1.0.1)
the print log is as follows:
Using TensorFlow backend.
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
DEBUG:root:Loading data...
DEBUG:root:image_dim_ordering = 'tf'
DEBUG:root:Creating model...
DEBUG:root:Model summary...
DEBUG:root:Saving model...
DEBUG:root:Running training...
Train on 154666 samples, validate on 17186 samples
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
Can u give me some advice about this ?
Hello,
I have modified the demo.py code for detecting ages and genders for images as an input instead of the webcam feed.
I was wondering, the pretrained_model; is it trained with the IMDB dataset?
I am using images of 6 different emotion recognition datasets but for females, it often classifies them as male.
Also, the ages aren't well-estimated. For an 70 year old male it classifies him as a 27 year old male.
I realize that this is due the fact that the images I use are very different from how the network is trained.
(eg. 576 x 720 size images)
Should I re-train the algorithm with the IMDB dataset or is this un-needed work?
I only have around 1500 images so I was assuming that it being trained on 500.000 images should be enough.
I am using images from MMI dataset, Cohn-Kanade dataset, etc.
Or do you suggest another age- gender recognition network that would be better to use for my case?
Afaik this code
https://github.com/yu4u/age-gender-estimation/blob/master/demo.py#L99
https://github.com/yu4u/age-gender-estimation/blob/master/create_db.py#L56
breaks aspect ratio of an input image.
But from what I see here https://data.vision.ee.ethz.ch/cvl/rrothe/imdb-wiki/ cropped images are perfect squares padded using cv2.BORDER_REPLICATE strategy.
Could you please confirm which resizing strategy or input datasets you used for training?
Either cropped square images only, or full dataset with additional face detection of your own.
Hello, I have a small issue with the code.
First of all, thanks so much for providing us with this code!
In the demo.py the code looks as follows:
#Get BGR in order for the detector to work.
input_img = cv2.cvtColor(img.astype('uint8'), cv2.COLOR_GRAY2BGR)
detected = detector(input_img, 1)
img_h, img_w, _ = np.shape(input_img)
faces = np.empty((len(detected), img_size, img_size, 3))
for i, d in enumerate(detected):
x1, y1, x2, y2, w, h = d.left(), d.top(), d.right() + 1, d.bottom() + 1, d.width(), d.height()
xw1 = max(int(x1 - 0.4 * w), 0)
yw1 = max(int(y1 - 0.4 * h), 0)
xw2 = min(int(x2 + 0.4 * w), img_w - 1)
yw2 = min(int(y2 + 0.4 * h), img_h - 1)
cv2.rectangle(input_img, (x1, y1), (x2, y2), (255, 0, 0), 2)
faces[i, :, :, :] = cv2.resize(input_img[yw1:yw2 + 1, xw1:xw2 + 1, :], (img_size, img_size))
# predict ages and genders of the detected faces
results = model.predict(faces)
However, is there any way to use the model.predict(faces)
on the input image?
This is because in an earlier stage, I already detected and extracted the faces of the subject that I am working with. This is the input image that I am trying to feed in. This means it is a time loss to do this again, and sometimes the faces can't be detected due to it already being cropped.
When I use the model.predict on the original image, I of course get an error; being:
Error when checking : expected input_11 to have 4 dimensions, but got array with shape (224, 224, 3)
Which is expected. However, is there a simple way to get past this?
The algorithm I am workng with has as output:
cut_image = img[y_m-he:y_m+he,x_m-wi:x_m+wi]
cut_image = cv2.resize(cut_image,(width,height), interpolation = cv2.INTER_AREA)
Thanks so much
hello, I want to run predict.ipny. But it seems to need WRN_16_8.json
So where to get WRN_16_8.json
?
looking forward to your reply.
The loss of age does not decrease, about equal 3.6
Which of the IMDB-wiki and UTKface performs better? I find that some labels were wrong on IMDB-wiki, so I used UTKface
Thank you for sharing, I have a question. When using cam to test, the face is almost unchanged, but the probability of the model output is very unstable. Do you have any good solutions?
Hello,
I am trying to train the model using the LAP dataset, but I am not sure how to do it.
I downloaded the training dataset with the images and th CVS file. Can you tell me how to change the code and traing the model with this dataset.
The model is too heavy for the cpu to process. So i want to resize the image to 128x128 before training. How can I optimize it by resizing the input?
Hey Yusuke
This is a continuation from issue 17.
After i ran train.py, I generated checkpoints, along with these files:
In you predict.ipynb, I changed the
model.load_weights(os.path.join("pretrained_models",
"weights.18-4.06.hdf5"))
to
model.load_weights("WRN_16_8.h5")
And I'm getting this odd error:
ValueError: Dimension 0 in both shapes must be equal, but are 131072 and 32768 for 'Assign_137' (op: 'Assign') with input shapes: [131072,2], [32768,2].
Any ideas where I might've gone wrong? I made sure I am using same widenet_res.py in both training and in prediction
BTW, I changed the nb_epoch from 30 to 100 during training but i doubt this is the cause...?
I would like to train the model with imagenet and see if it can improve the performance. Can you please give me a script that can seperate the imdb dataset to various folders with respect to the age?
It seems like you're feeding RGB images to the Net in demo
https://github.com/yu4u/age-gender-estimation/blob/master/demo.py#L83
But looks like it is trained on BGR default opencv images:
https://github.com/yu4u/age-gender-estimation/blob/master/create_db.py#L55
Please clarify. And, btw, what are the image size you used for pretrained model provided (weights.28-3.73.hdf5)? Thank you in advance.
Hi
First of all, thanks for this work. My question is that can I use the pre-trained weights you provide in an android application? if so, how can I create the .pb file for this purpose?
Thanks in advance,,
Hi there,
I'm confused about this calculation in demo.py
:
results = model.predict(faces)
predicted_genders = results[0]
ages = np.arange(0, 101).reshape(101, 1)
predicted_ages = results[1].dot(ages).flatten()
Why is there a dot product calculated instead of index with max value?
Imagine the following scenario with one face with this output:
results[1]:
[[6.88381488e-06 4.99174821e-05 5.31654223e-05 8.81420328e-06
3.14831013e-05 4.00605095e-05 4.33792193e-05 5.87120885e-05
4.47424136e-05 7.89339829e-05 9.78237658e-05 2.98563100e-04
5.30292047e-04 1.20672619e-03 4.25174553e-03 6.22432539e-03
1.31485937e-02 1.25159947e-02 2.79996358e-02 2.95896754e-02
4.22185808e-02 4.98768501e-02 8.72164890e-02 8.13968405e-02
4.06013280e-02 7.37321898e-02 6.11355454e-02 5.95830940e-02
5.18204570e-02 6.64811879e-02 4.87477817e-02 2.88283490e-02
5.48146665e-02 2.56483611e-02 1.41099067e-02 1.93021428e-02
1.27679640e-02 2.21271571e-02 8.21464416e-03 9.39735305e-03
7.45108770e-03 7.62853073e-03 4.46106028e-03 3.77128413e-03
3.19997105e-03 3.59987095e-03 1.93364581e-03 2.93601328e-03
2.00799946e-03 1.00616459e-03 1.59712264e-03 6.33452029e-04
5.70641481e-04 4.81930183e-04 4.77437454e-04 3.11825279e-04
3.33868637e-04 3.99059849e-04 3.31061863e-04 3.73236981e-04
3.08186543e-04 1.56975817e-04 1.60575451e-04 2.16696353e-04
2.38688110e-04 1.83488766e-04 9.20830789e-05 1.01336227e-04
9.11841635e-05 6.63516548e-05 6.84541301e-05 6.43297026e-05
6.82058817e-05 5.28406053e-05 4.04599705e-05 3.28831848e-05
2.44612365e-05 2.94256006e-05 2.54540537e-05 3.53251671e-05
1.79423114e-05 9.23900279e-06 1.36023336e-05 1.01442247e-05
1.07303895e-05 6.55067834e-06 5.72359386e-06 6.08522032e-06
5.98073939e-06 6.34011349e-06 4.15177055e-06 3.75096920e-06
4.02725482e-06 4.76177183e-06 4.53801522e-06 3.85877502e-06
4.49254321e-06 3.67203666e-06 4.07408197e-06 3.67203666e-06
3.67203666e-06]]
The biggest probability is 8.72164890e-02
with index 22, however, using the calculation currently implemented, result is 26.89 and predicted age is therefore 26. Why? Is pretrained model really trained this way?
Im using the following code to convert the keras model to tensorflow.
from wide_resnet import WideResNet
from keras.layers.core import K
import tensorflow as tf
import os.path as osp
K._LEARNING_PHASE = tf.constant(0)
input_fld = 'input'
weight_file = 'weights.18-4.06.hdf5'
num_output = 1
write_graph_def_ascii_flag = True
prefix_output_node_names_of_final_network = 'softmax'
output_graph_name = 'age_weight_two.pb'
output_fld = input_fld + 'tensorflow_model/'
img_size = 64
model = WideResNet(img_size, depth=16, k=8)()
model.load_weights("input/weights.18-4.06.hdf5")
pred = [None]*num_output
pred_node_names = [None]*num_output
for i in range(num_output):
pred_node_names[i] = prefix_output_node_names_of_final_network+str(i)
print (pred_node_names[i] )
pred[i] = tf.identity(model.output[i], name=pred_node_names[i])
print('output nodes names are: ', pred_node_names)
sess = K.get_session()
if write_graph_def_ascii_flag:
f = 'only_the_graph_def.pb.ascii'
tf.train.write_graph(sess.graph.as_graph_def(), output_fld, f, as_text=True)
print('saved the graph definition in ascii format at: ', osp.join(output_fld, f))
from tensorflow.python.framework import graph_util
from tensorflow.python.framework import graph_io
constant_graph = graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), pred_node_names)
graph_io.write_graph(constant_graph, output_fld, output_graph_name, as_text=False)
print('saved the constant graph (ready for inference) at: ', osp.join(output_fld, output_graph_name))
In my prediction, I run the prediction as follows,
sess.run(softmax_tensor, feed_dict={'input_1:0': faces})
However it throws the following error,
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'batch_normalization_1/keras_learning_phase' with dtype bool
[[Node: batch_normalization_1/keras_learning_phase = Placeholderdtype=DT_BOOL, shape=, _device="/job:localhost/replica:0/task:0/cpu:0"]]
How can I be able to sort this out?
Hi @yu4u ,
Where can the weights found here age only weights be used? Can I use it normally while running demo?
I tried running it in the demo.py script and got this error, so I assume my depth and width of the model should be changed accordingly. Any leads on that?
ValueError: You are trying to load a weight file containing 107 layers into a model with 31 layers.
Hi,
I've been doing some simple analysis over both pre-trained models, validating using appa-real dataset.
Here's what I'm doing:
For each cropped and rotated image i.e. (_face.jpg) prefix:
Note that I'm using real_age as supplied by appa dataset and not the expected value of apperent_age.
In total I've sampled 1978 images, I see that:
I'm attaching some plots I've done, where my goal is to find if either I'm doing something incorrectly or maybe the accuracy is just off a bit? Maybe best to re-train on another dataset?
Again, thank you @yu4u for this project, I'm assuming I'm at fault here. Would love to get your feedback.
Hello ,
for the error on train.py: the following arguments are required: --input/-i
I've already download the image data set. I'd like to know how to change the data to .mat and how to use train.py to training my model.Thanks
Why is that the frame is too slow. It is lagging. How do I optimize it
Thank you @yu4u for this project.
I have some questions. In your project, you have trained on imdb dataset and tested on wiki dataset, but can you tell me the specific test age MAE and gender accuracy?
Hi!
I have some trouble with launching.
Mac OS 10.13 High Sierra, Macbook white 2010.
I tried to launch demo.py
script by
python3 demo.py
but the issue Illegal instruction: 4
has occured. I know it could happen as my notebook is too old and processor is not understand some instructions of dlib. I tried to change SSE4 to SSE2 instructions before dlib recompiling but dlib was updated to 10.13 and I can't find the necessary strings in CMakeLists.txt
currently. What should I do to launch demoscript?
This code is written and run perfectly, but when I use this code in Flask+Gunicorn which is multithread, it will throw:
ValueError: Tensor Tensor("predictions_1/Softmax:0", shape=(?, 2), dtype=float32) is not an element of this graph.
I search in stackoverflow, found this is caused by Keras. Link is https://github.com/fchollet/keras/issues/2397 and solution is what ‘avital ’ and ‘jglwiz’ said:
keras with tensorflow backend.
Details:
global thread:
self.model = load_model(model_path)
self.model._make_predict_function()
self.graph = tf.get_default_graph()
another thread:
with self.graph.as_default():
labels = self.model.predict(data)
but how can I modify our code ?( I am totally a newbie in Keras ... Sorry ...)
I tried following code but made no sense, maybe "load_weights" is different with "load_model" method:
Global:
self.agegender_classifier = WideResNet()()
self.agegender_classifier.load_weights(agegender_emotion_model_path)
self.agegender_classifier._make_predict_function()
self.agegender_graph = tf.get_default_graph()
Predict:
with self.agegender_graph.as_default():
results = self.agegender_classifier.predict(faces_agegender)
When I run this model on video, i've noticed the prediction changes pretty wildly from frame to frame, depending on the face dimensions, lighting, position, etc. But as soon as the face becomes closed to the camera, the predictions are more consistent.
Two questions
I have used tensorflow but the output is too laggy even after reducing the depth.
So how do we use theano to optimize the performance?
I succeeded running the program with tensorflow without gpu. However, I can't run the program with tensorflow with gpu.
The following error appears when I run the program:
Using TensorFlow backend.
2017-07-05 10:18:44.115782: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:893] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2017-07-05 10:18:44.116126: I tensorflow/core/common_runtime/gpu/gpu_device.cc:938] Found device 0 with properties:
name: GeForce GTX 1050
major: 6 minor: 1 memoryClockRate (GHz) 1.468
pciBusID 0000:01:00.0
Total memory: 1.95GiB
Free memory: 1.72GiB
2017-07-05 10:18:44.116175: I tensorflow/core/common_runtime/gpu/gpu_device.cc:959] DMA: 0
2017-07-05 10:18:44.116189: I tensorflow/core/common_runtime/gpu/gpu_device.cc:969] 0: Y
2017-07-05 10:18:44.116214: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1028] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0)
Illegal instruction (core dumped)
Does this program compatible with tensorflow with gpu?
The system I am using is list as following:
Ubuntu 16.04,Python 2.7.12 ,Keras 2.0.5,Tensorflow 1.2.0,CUDA 8.0, V8.0.61
,cuDNN 6.0
Hi,
I would appreciate if you share pre-trained models and checkpoints, so that I could download it and evaluate the model. Pre-trained model might be small, just for demo purposes.
Thank you a lot,
I really like your project.
I think plot_accuracy.py should be changed in order to reflect the changes made to train.py
from dense_2_acc to pred_age_acc and val_dense_2_acc to val_pred_age_acc, etc
Hi Yusuke. Thanks your repo firstly. It helps me a lot. My work following your repo is as below:
1, I cleaned the imdb dataset manually and converted them to imdb_zz.mat.
2, Training on imdb_zz.mat. --aug Ture, depth 16 width 8 as default. num_epochs 30.
3, the minimum val_loss is 3.49 and the weights stored as weights.25-3.49.hdf5.
4, Using weights.25-3.49.hdf5 to predict images. I test on LAP dataset as References[2] mentioned. However, my score is much worse than References[2] as discribled in title and it predicts young people(age<15) badly.
i am looking forward to your reply and any advice is welcomed.
Thank you.
Hi, I really appreciate your neat code and it works perfectly. However, it seems the age estimation accuracy on validation set is quite low and seems only attend 0.04. I guess it is due to the number of classes. But would the model predict better if I reduce the class number?
In addition, I re-checked your accuracy curve and observed that it might overfit when epoch over 25.
Thanks
Im testing your code on different attributes: gender & ethnicity, where ethnicity is one of 7:
ethnicity_map = {
"Asian" : 0,
"Black" : 1,
"Caucasian" : 2,
"Hispanic" : 3,
"Indian" : 4,
"Middle Eastern" : 5,
"Native American" : 6
}
def ethnicity_category(eth):
return ethnicity_map[eth] if eth in ethnicity_map else None
Then I follow your procedure for generating /reading the matlab file
out_genders = []
out_ethnicities = []
out_imgs = []
df = pd.read_csv("../STEP3/data.csv")
for index,row in df.iterrows():
gender = 1 if (row["gender"].strip() == "Male") else 0
ethnicity = ethnicity_category(row["ethnicity"].strip())
image = row["image"].strip()
if(ethnicity is not None):
out_genders.append(gender)
out_ethnicities.append(ethnicity)
img = cv2.imread("../STEP3/data/{}".format(image))
out_imgs.append( cv2.resize(img, (img_size, img_size)) )
output = {
"image" : np.array(out_imgs),
"ethnicity": np.array(out_ethnicities),
"gender" : np.array(out_genders),
"img_size" : img_size,
}
scipy.io.savemat(output_path, output)
Every other parameter is the same (including img_size).
For reading the weights:
X_data = image
y_data_g = np_utils.to_categorical(gender, num_classes=2)
y_data_e = np_utils.to_categorical(ethnicity, num_classes=8)
I changed wide_resnet.py from
predictions_g = Dense(units=2, kernel_initializer=self._weight_init, use_bias=self._use_bias,
kernel_regularizer=l2(self._weight_decay), activation="softmax")(flatten)
predictions_a = Dense(units=101, kernel_initializer=self._weight_init, use_bias=self._use_bias,
kernel_regularizer=l2(self._weight_decay), activation="softmax")(flatten)
model = Model(inputs=inputs, outputs=[predictions_g, predictions_a])
to
predictions_g = Dense(units=2, kernel_initializer=self._weight_init, use_bias=self._use_bias,
kernel_regularizer=l2(self._weight_decay), activation="softmax")(flatten)
predictions_e = Dense(units=7, kernel_initializer=self._weight_init, use_bias=self._use_bias,
kernel_regularizer=l2(self._weight_decay), activation="softmax")(flatten)
model = Model(inputs=inputs, outputs=[predictions_g, predictions_e])
And I am getting this error when i start training:
ValueError: Error when checking target: expected dense_2 to have shape (None, 7) but got array with shape (75797, 8)
Any ideas?
Hi,yu4u,
I am a student, I need to learn age and gender estimation for my graduation design. I'm using my computer to use IMDB-WIKI dataset to train the model,but this process takes a long time, It takes about 4 hours one epoch. Can you give me your checkpoint folder? I promise I won't use it for any commercial purpose. Thank you very much.
When I was running demo.py, I found that the template of weights.18-4.06. Hdf5 was time-consuming to predict, so I felt whether the template could be improved
I have run python3 demo.py
code
and I got this
/usr/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88 return f(*args, **kwds) Using TensorFlow backend. /usr/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88 return f(*args, **kwds) /usr/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88 return f(*args, **kwds) Downloading data from https://github.com/yu4u/age-gender-estimation/releases/download/v0.5/weights.18-4.06.hdf5 195813376/195810464 [==============================] - 56s 0us/step 2018-07-24 16:57:16.697715: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA VIDEOIO ERROR: V4L: can't open camera by index 0 Traceback (most recent call last): File "demo.py", line 121, in <module> main() File "demo.py", line 82, in main for img in yield_images(): File "demo.py", line 60, in yield_images yield img File "/usr/lib/python3.5/contextlib.py", line 77, in __exit__ self.gen.throw(type, value, traceback) File "demo.py", line 42, in video_capture yield cap File "demo.py", line 58, in yield_images raise RuntimeError("Failed to capture image") RuntimeError: Failed to capture image
NOTE: I'm on Ubuntu 16.04 installed in VMware and I have a webcam in my laptop, I think I've installed all the dependencies correctly
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.