chaquo / chaquopy

Chaquopy: the Python SDK for Android
https://chaquo.com/chaquopy/
MIT License
807 stars 132 forks source link

Requesting a newer version of tensorflow. #1073

Closed MustofAhmed41 closed 8 months ago

MustofAhmed41 commented 8 months ago

My Goal is to train a small neural network model(keras) using chaquopy. I have also discussed about this issue in #1069

Chaquopy version

Chaquopy version: 14.0.2 Python version: 3.8 Tensorflow version that gets installed by default is 2.1.0.

Devices or emulators where the issue happens

Both Devices and emulators

Relevant parts of your code


1. from keras.models import Sequential
2. from keras.layers import Dense
3. 
4. model = Sequential()
5. model.add(Dense(100 , input_shape=(500, ) ,  activation='relu'))  
6. model.add(Dense(1),  activation='softmax' )
7. model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

Describe your issue

The line 5 throws an error occurs when I include 'input_shape' parameter. If I run it without input_shape, it doesn't throw error. I tried to install other version of tensorflow by downloading .whl file, but in that case I used to get this build error "Could not find a version that satisfies the requirement tensorflow==2.6.5 (from versions: 2.1.0)". I am not sure but I am hoping using a newer version of tensorflow might help in fixing this error.

Error message in line 5

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.fl2, PID: 5982 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fl2/com.example.fl2.MainActivity}: com.chaquo.python.PyException: TypeError: list indices must be integers or slices, not str at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) Caused by: com.chaquo.python.PyException: TypeError: list indices must be integers or slices, not str at .google.protobuf.internal.containers.getitem(containers.py:70) at .tensorflow.python.framework.ops._NodeDef(ops.py:1569) at .tensorflow.python.framework.ops._create_op_internal(ops.py:3307) at .tensorflow.python.framework.func_graph._create_op_internal(func_graph.py:593) at .tensorflow.python.framework.op_def_library._apply_op_helper(op_def_library.py:740) at .tensorflow.python.ops.gen_array_ops.placeholder(gen_array_ops.py:6031) at .tensorflow.python.ops.array_ops.placeholder(array_ops.py:2718) at .tensorflow.python.keras.backend.placeholder(backend.py:1054) at .tensorflow.python.keras.engine.input_layer.init(input_layer.py:122) at .tensorflow.python.keras.engine.input_layer.Input(input_layer.py:270) at .tensorflow.python.keras.engine.sequential.add(sequential.py:180) at .tensorflow.python.training.tracking.base._method_wrapper(base.py:457) at .my_script.train_model(my_script.py:10) at .chaquopy_java.call(chaquopy_java.pyx:379) at .chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrowsNative(chaquopy_java.pyx:351) at com.chaquo.python.PyObject.callAttrThrowsNative(Native Method) at com.chaquo.python.PyObject.callAttrThrows(PyObject.java:232) at com.chaquo.python.PyObject.callAttr(PyObject.java:221) at com.example.fl2.MainActivity.onCreate(MainActivity.java:27) at android.app.Activity.performCreate(Activity.java:8000) at android.app.Activity.performCreate(Activity.java:7984) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

mhsmith commented 8 months ago

Sorry, we won't have time to upgrade TensorFlow for the foreseeable future (https://github.com/chaquo/chaquopy/issues/374#issuecomment-1816699326). But this specific error may be possible to work around by downgrading protobuf – see https://github.com/chaquo/chaquopy/issues/1069#issuecomment-1882655659.