Human Activity Recognition in Android || Tensorflow Android || Developers Hutt
Вставка
- Опубліковано 11 січ 2025
- In this video, you'll learn to train a machine learning model from scratch using Tensorflow and Keras on Smartphone sensor data to predict the physical activity of a person.
And you'll also learn to deploy it on an Android device using Java in Android Studio that works offline.
There are so many things ahead. So keep updated on: developershutt
Android App for recording your own dataset: github.com/dev...
Link to download dataset: www.utwente.nl...
Source code for model training: github.com/man...
Source code for Android App: github.com/man...
Please leave your feedback and if you have any topic related to machine learning, Deep Learning, Android, or Mathematics please let me know in the comments.
Thanks
~-~~-~~~-~~-~
Please watch: "Modern/Best Resume for Programmers"
• Modern/Best Resume for...
~-~~-~~~-~~-~
You have so much of knowledge in this age. Great man . Keep going
WOW, man, your video is such a tremendous resource. Many thanks putting this together.
I'm having a hard time doing freeze_graph. I'm getting an 'IndexError: list index out of range' error and I don't know what the problem is.
Overfitted model
@@DevelopersHutt how to solve this
@@furqansiddiqui5765 it's a version conflict I think.
Train your model using TF 1.13 and save it using TF 1.8
wow, amazing. you help me so much in this field, ty
for the result in predictActivity, how do you know the order of the array to be [biking, downstairs, jogging, sitting, standing, upstairs, walking] ?
The same order you've used while training should be used while inferencing in Android
thanks man , very helpful , keep up the good work
Thank you so much
Hi i am looking for a deep learning expert for developing a model for yoga pose estimation and correction feedback for my Phd work. Can you help me out.
Hi, Could you please elaborate more at merging point of two participants, when the time series data is generating?
If I want to merge dataset on accelerometer and gyroscope from different sources to get information over more activities together, then if I just merge evrything together, how can I make windows from that.?
Or if we make windows, extract features from each dataset seperately., then just merge one after another , Will it be right procedure?
Or am I missing any concept??
The merging I've performed in the video because the data was collected from 8 different android devices. But the structure of the datasets are same (columns). Hence I merged it as it was. So if you want to merge the data different sources, you've to put right values in right column. That's it.
What exact version of tensorflow,keras have to use
As in vdo it specified some diff as in git link it's different?
It is really a great project.
Thank you so much.
But one thing is contradicting because you said that this data is Time Series Data and on the other hand you are dropping time column why?
And Suppose I want to merge data from other sources which contain accelorometer and gyroscope can I merge because that data has different time stamp and extra activities if yes then please let us know and if not then why???
I hope to get reply by tomorrow as soon as possible thank you once more
The dropped columns contained values from sensor which my device doesn't has. That's why I dropped them.
Offcourse you can append new data into old data. The old dataset contains raw values from sensor so you just need to remember that only raw values can ve appended.
'The file was loaded in a wrong encoding 'UTF-8'. This error shows up when I try to open model.pb file. Why ?
Very nice keep it up 👍
Thank you, I will
sir can you please help mee i'm getting a value error while dataset into time series sequence?
Hello, in this project, why is the value the highest for jogging only? Is there any way to remove this error?
This model was trained on collected data from my old device. And just because sensor calibrations are different, it showings jogging as highest prob. You can collect you own data and retrain the model to get it fixed
Hello brother, I am following your video but I am getting an error with the lstm layer which says no op kernel supports the op clipbyvalue in android studio. Would really appreciate if we can discuss and I can share this with you cos mine is for a fall detection. I am doing this for a uni project. Please help, thanks
Are you using the same tensorflow version as I did in android?
hey am getting this errror:Failed to run TensorFlow inference with inputs:[lstm_1_input], outputs:[output/Softmax] while running the code in android studio could someone help me?
Are you using the same tensorflow version as I did in android?
While running this code - -
tf.train.write_graph(k.get_session().graph_def,'models',model_name + '_graph.pbtxt')
saver=tf.train.Saver()
saver.save(k.get_session(),'models/'+model_name+'.chkp')
I get the following error ----
module 'tensorflow._api.v2.io' has no attribute 'train'
I am using tensorflow 2.7.0. It has something to do with the version ? Please help me fix it.
Use tensorflow 1.8 or 1.13
How to collect dataset using the given app
One more thing in your github codes, you have used tensorflow 2.3 in for the training model but in android studio, you are using tensorflow 1.8. Isn't there any compatibility issue ?
Nope
Sir, please explain what type of machine learning algorithm you are using.
Model with Long short term memory
@@DevelopersHutt Okay, thanks alot :)
Hi sir, thank for the sharing. I have a question, how to add sensitivity and specificity in the coding?
I didn't get it. What does that mean "add sensitivity"
@@DevelopersHutt it’s the trio performance evaluation for machine learning. Usually people will include accuracy,sensitivity and specificity together in their machine learning performance results.
Will it show correct output as walking if I hold phone in hand walk
The model trained in the video was on a dummy dataset just to demonstrate how it can be done. If you collect dataset of doing activities while holding a phone in your hands and train a model like you saw in the video. It will work!
can you help me in finding another dataset of same project
because this output mostly to jogging only
I got that dataset from kaggle. Not sure if there is an update one as well .
Hi Sir, Thanks a lot for the great tutorial. I follow your GitHub repo to save the model on Tensorflow version 2. Could you please help me to know the input and output nodes' names on your GitHub repo codes? I need to deploy on android. Thank you
Hİ, thanks a lot for this great project from scratch. I really enjoyed your video and your detailed github repo. I have a question. I have installed your apk to test the model and the project, but as it shows in your video it almost always show the jogging in high probability. I have created the model in python thanks to you, but when I checked your apk, the results are almost wrong! what would be the problem? is the model you use in project is wrong?
It might be problem of sensor calibration
@@DevelopersHutt Thank you for this amazing project!!. But it always shows jogging while sitting or doing any other activity. Can you please resolve the issue and update the repo?? It would be of great help.
@@shubhi9540 Thank you for thr feedback. I will try to resolve it ASAP
@@DevelopersHutt did this problem is solved?
Same problem? How to resolve
Is this project compatible with the wear os? I mean can this project be built for the wearable devices?
With right data. Yes
A Dumb question did you use Keras Classifier?
Yes
Good work!!
Thank you! Cheers!
Sir this project is really interesting, can you please specify which version of python have you used in the virtual envionment?
Python 3.6
@@DevelopersHutt Thank you sir ..Great work 👍👍
is it necessary that numpy version should be 1.14 only? because the numpy version is clashing with other requirements version
@@Falguni.R it executed on my pc on that version that's why I suggested only.
But if you want you can change version according to the other dependencies you have. It's absolutely not a big deal
@@DevelopersHutt okay ..that means it won't affect the final output sir if I do so ?
When I click on Run, my app just starts and closes instantly and when I click on Logcat, it does not show the activities. What could be the possible reason ? I have followed all your steps.
What's the error when app crashes
Caused by: java.io.IOException: Not a valid TensorFlow Graph serialization: NodeDef expected inputs 'variant' do not match 2 inputs specified; Op tensor:element_dtype; attr=element_dtype:type; attr=num_elements:int,default=-1>; NodeDef: sequential/lstm_1/PartitionedCall/TensorArrayV2Stack/TensorListStack = TensorListStack[element_dtype=DT_FLOAT, num_elements=-1](sequential/lstm_1/PartitionedCall/while/exit/_51, sequential/lstm_1/PartitionedCall/TensorArrayV2Stack/TensorListStack/element_shape)
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.loadGraph(TensorFlowInferenceInterface.java:561)
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.(TensorFlowInferenceInterface.java:105)
at com.developershutt.har.ActivityClassifier.(ActivityClassifier.java:23)
at com.developershutt.har.MainActivity.onCreate(MainActivity.java:53)
at android.app.Activity.performCreate(Activity.java:7088)
at android.app.Activity.performCreate(Activity.java:7079)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2895)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1616)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:6651)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)
2022-04-04 23:43:37.090 9560-9560/com.developershutt.har I/Process: Sending signal. PID: 9560 SIG: 9
Also, when I open model.pb file in Android Studio, it shows incorrect file encoding 'UTF-8'. Are these errors because of the model.pb file?
@@furquananwer1844 I am also facing the same problem bro
@Developers Hutt please reply
very helpful. ONE ERROR : while freezing the model (last task on jupyter notebook), i get this error : ''IndexError: list index out of range'
I have matched the tensorflow version as yours but the error persists. Please guide.
Please switch to tf 1.14.0 and try again
@@DevelopersHutt Hi I am facing the same issue with the error 'IndexError: list index out of range' when running the final line of code. I have switched to tf 1.14 as suggested, but still not working. Please provide any help
That's weird! Please send me your notebook at huttofdevelopers@gmail.com
@@DevelopersHutt I have sent my notebook via email and we may chat there. Thank you very much
@@chiyedza9590 what was the solution?
Kindly help
the dataset link doesnt have any data in it
what android phone are you using? Mine log tells that sensor is null.
Motorola moto G5S Plus
@@DevelopersHutt why is the prediction always wrong? most of the time it tells "jogging" although im sittin'..
@Adam Heinrich Check if the labels are in position where it should be. Like maybe you put jogging label in place of sitting. Also do some feature engineering or try out different dataset. There are more dataset on internet on Human Activity Recognition.
What does IT mean feature engineering?
I used yours model from guthub
Amazing video
Bhai ye machine learning and deep learning kaha se karu?? Merko itna karna hai ki aapka video samajh pau.
Ml aata hai thoda bohot. Basic algorithms ke working and numpy pandas sab aate hain. Ye aapne jo deep learning use kia hai iss video mei.. where do i learn that??
Agar basic machine learning aati h (jaise Linear Regression, Logistic Regression, SVM etc) to fir ye book best hogi Deep Learning start karne k liye.
1. Hands-on Machine Learning with Scikit Learn and Tensorflow
Buy link: amzn.to/3CEoaId
@@DevelopersHutt thank you sir
Can you plz tell how does it work and how it shows output
Like if I am holding my phone and walking will it detect and show walking as output
Java.lang.Runtime Exception:failed to load model from ‘model.pb’
SOLUTION?
Check model path
What input you are giving to the android app?
Values from accelerometer and gyroscope sensor
@@DevelopersHutt How can I check where the results are correct or not?Is there a way to enter raw data and check?/
Bhaiyya mene sab kuch kia video ke according. Mene apk build kia and wo install bhi hogaya mere device mei but app crash ho raha. It doesn't open.
Android version : android 12
Bhaiyya please help kardijiye. Final year project yahi kar raha mei and agar app nahi chala toh kaafi dikkat hojaegi
Koi permission ka error hoga. Logs send karo ho sake to.
To stackoverflow pe post karke share kar do yaha
@@DevelopersHutt
2022-04-20 15:45:34.951 3169-3169/com.developershutt.har E/TensorFlowInferenceInterface: Failed to run TensorFlow inference with inputs:[lstm_1_input], outputs:[output/Softmax]
2022-04-20 15:45:34.952 3169-3169/com.developershutt.har E/SensorManager: Exception dispatching input event.
2022-04-20 15:45:34.952 3169-3169/com.developershutt.har D/AndroidRuntime: Shutting down VM
--------- beginning of crash
2022-04-20 15:45:34.953 3169-3169/com.developershutt.har E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.developershutt.har, PID: 3169
java.lang.IllegalArgumentException: No OpKernel was registered to support Op 'ClipByValue' with these attrs. Registered devices: [CPU], Registered kernels:
[[Node: lstm_1/while/clip_by_value = ClipByValue[T=DT_FLOAT](lstm_1/while/add_2, lstm_1/while/Const, lstm_1/while/Const_1)]]
at org.tensorflow.Session.run(Native Method)
at org.tensorflow.Session.access$100(Session.java:48)
at org.tensorflow.Session$Runner.runHelper(Session.java:298)
at org.tensorflow.Session$Runner.run(Session.java:248)
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.run(TensorFlowInferenceInterface.java:228)
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.run(TensorFlowInferenceInterface.java:197)
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.run(TensorFlowInferenceInterface.java:187)
at com.developershutt.har.ActivityClassifier.predictProbabilities(ActivityClassifier.java:29)
at com.developershutt.har.MainActivity.predictActivity(MainActivity.java:113)
at com.developershutt.har.MainActivity.onSensorChanged(MainActivity.java:88)
at android.hardware.SystemSensorManager$SensorEventQueue.dispatchSensorEvent(SystemSensorManager.java:837)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:336)
at android.os.Looper.loop(Looper.java:174)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
this is the error log bhaiyya. pls dekh lijiye
Kaha hai?
i am using anaconda navigator were do i put my dataset file for the code to work
At same path where your code exists
@@DevelopersHutt you are taking only values in left and right pocket if the girls are using they does not wear a pants with pockets how does the sensors detect their actiivty
@@SoorajRS-h8z that was just a demo about how you can build such system. For the real world, you have to collect diverse amounts of data to train the model.
This data would not be enough
OSError: Input graph file 'models/har_model_graph.pbtx' does not exist!
THE LAST CELL OF JUPYTER NOTEBOOK RAISING ERROR PLEASE REPLY all things worked fine but at last cell of jupyter I am getting error please tell me how to fix it ..................
### freeze_graph.freeze_graph('models/'+model_name + '_graph.pbtx',None, False,'models/'+model_name+'.chkp',
output_node_name,'save/restore_all','save/Const:0','models/frozen_' + model_name + '.pb', True,"") ###
Use tensorflow 1.8 for this
Use tensorflow 1.8 for this
can we find time between Activities?
I didn't get it. Please explain
Why it's shows jogging while u sitting
I've custom rom in my device and the sensor wasn't calibrated correctly.
error : "failed to load model from model.pb"
how to fix this error? :(
Make sure you put protobuffer file (filename.pb) on the location mentioned in function.
@@DevelopersHutt I can't install tensorflow 1.13.1
Is it possible to run this code with tensorflow 2.3.0 ?
@@md.hafizurrahman5590 no actually.
Still you've 2 ways to run the code
1. if you want to run code on tf 2+ than tensorflow has a converter that will convert tf 1 source code to tf 2 equivalent.
2. Create a virtual environment using venv and install tf 1.13.1 there. It won't affect anything outside environment.
@@DevelopersHutt I need your help. May I get your Skype ID?
@@DevelopersHutt I trained model on tensorflow 2.2.0 version and freeze graph into model.pb file. then store this model.pb file into assets folder. But it shows same error "failed to load model from model.pb"
I have an error while running
freeze_graph.freeze_graph('models/'+model_name + '_graph.pbtxt', None, False, 'models/'+model_name+'.chkp',
output_node_name, 'save/restore_all', 'save/Const:0', 'models/frozen_' + model_name + '.pb', True, "")
stackoverflow.com/questions/64418331/cannot-run-the-method-freeze-graph-index-out-of-range
I described it here,could you help?
I trained this model once and I succesfully exported it to Android,don't get the mistake now. Thanks
I've gone through it. Please post complete error you've got
@@DevelopersHutt here?
Would be better if you post on stackoverflow
@@DevelopersHutt stackoverflow.com/questions/64418331/cannot-run-the-method-freeze-graph-index-out-of-range
I have updated the post,whole error is now shown.
@@DevelopersHutt can you notice mine mistake?
While freezing Model it shows FailedPreconditionError
Which version of tensor flow you're using??
@@DevelopersHutt1.13.1
now issue has been solved. package was not installed properly due to conflict
@@DevelopersHutt Thank you Great work :)
My pleasure, Stay tune for more 🙏
bhaiyya android development kaha se seekhu?
Intro k liye ye video follow kar lo
ua-cam.com/video/fis26HvvDII/v-deo.html
Per fir Android official Docs se start kar do agar ache se seekhna h to. Usse best resource shayad koi ni h.
how to download this project
Link to the source code is given in description
Can you please share the dataset file
Didn't you find anything in the link??
@@DevelopersHutt no...in github it's not showing
Hey Riti, I've uploaded the dataset on Drive and you can download that from here : bit.ly/3r0IBuh
@@DevelopersHutt what is df.Ax ,df.Ay and df.Az...its showing error that datafram doesn't hav Ax attributes
Send the participants dataset that you used...this showing some errors
Is this real time project
Yes!
It was
All the steps work well until the fit_generator. Does anyone have idea how to solve it? Thanks
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:1: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
"""Entry point for launching an IPython kernel.
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
in ()
----> 1 history=model.fit_generator(train_gen, epochs=5, validation_data=test_gen, callbacks=callbacks)
2
3 frames
/usr/local/lib/python3.7/dist-packages/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
2221 use_multiprocessing=use_multiprocessing,
2222 shuffle=shuffle,
-> 2223 initial_epoch=initial_epoch)
2224
2225 @doc_controls.do_not_generate_docs
/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
65 except Exception as e: # pylint: disable=broad-except
66 filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67 raise e.with_traceback(filtered_tb) from None
68 finally:
69 del filtered_tb
/usr/local/lib/python3.7/dist-packages/pandas/core/frame.py in __getitem__(self, key)
3456 if self.columns.nlevels > 1:
3457 return self._getitem_multilevel(key)
-> 3458 indexer = self.columns.get_loc(key)
3459 if is_integer(indexer):
3460 indexer = [indexer]
/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3361 return self._engine.get_loc(casted_key)
3362 except KeyError as err:
-> 3363 raise KeyError(key) from err
3364
3365 if is_scalar(key) and isna(key) and not self.hasnans:
KeyError: 100
Which tensorflow and keras version you're using