chaquo / chaquopy

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

I am using cnn model .h5 file in android studio using chaquopy #529

Closed deepik27 closed 3 years ago

deepik27 commented 3 years ago

I want to use .h5 file in android studio using chaquopy for lane detection, but i am getting the error has below

com.chaquo.python.PyException: ImportError: cannot import name 'get_config' from 'tensorflow.python.eager.context

or please suggest me how to use model.h5 file using tensorflow

mhsmith commented 3 years ago

There are many examples of this error on StackOverflow. Have you tried changing your Keras import statements as shown in the answers to this question?

If that doesn't help, please post the full stack trace, and the relevant sections of your code.

deepik27 commented 3 years ago

Actually here is my model.h5 file link, i am getting same issue when i use with android studio and suppose if i use in visual studio i am not getting any issues, below i will attach the code also

https://drive.google.com/file/d/1UclOhWDd6o-VV388fj_9JXE1KeZMmLQO/view?usp=sharing

import numpy as np import cv2 from skimage.transform import resize from tensorflow import keras import pickle from moviepy.editor import VideoFileClip

model = keras.models.load_model('full_CNN_model.h5')

class Lanes(): def init(self): self.recent_fit = [] self.avg_fit = []

def road_lines(image):

recent_fit=[] avg_fit=[] small_img = resize(image,(80,160,3)) small_img = np.array(small_img) small_img = small_img[None,:,:,:]

prediction = model.predict(small_img)[0] * 255

recent_fit.append(prediction)

if len(recent_fit) > 5: recent_fit = recent_fit[1:]

avg_fit = np.mean(np.array([i for i in recent_fit]),axis=0)

blanks = np.zeros_like(avg_fit).astype(np.uint8)

lane_drawn = np.dstack((blanks,avg_fit,blanks)) print("Deepika", lane_drawn)

lane_image = resize(lane_drawn, image.shape)

result = cv2.addWeighted(image,1,lane_image,1,0)

return lane_image

mhsmith commented 3 years ago

And the full stack trace please.

mhsmith commented 3 years ago

If this is still a problem, please provide the requested information and I'll reopen the issue.

ImRaineJ commented 1 year ago

I want to use .h5 file in android studio using chaquopy for lane detection, but i am getting the error has below

com.chaquo.python.PyException: ImportError: cannot import name 'get_config' from 'tensorflow.python.eager.context

or please suggest me how to use model.h5 file using tensorflow

hi can i ask how you install keras in chaqoupy for you to use your model?

mhsmith commented 1 year ago

Keras now comes with TensorFlow, it doesn't need to be installed separately.