tensorflow (core dumped)

asked 2020-07-13 04:31:59 -0500

arafatsadasd gravatar image

updated 2020-07-13 13:04:37 -0500

Hello All

I have a tensor flow model that inputs an image and output a certain number I want to use the model to subscribe to the image seen by the robot in gazebo I have successfully connected ROS and Tensor flow to work both in Python three

#!/usr/bin/env python3

import rospy
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
import sys
sys.path.remove('/opt/ros/kinetic/lib/python2.7/dist-packages') # in order to import cv2 under python3
import cv2
sys.path.append('/opt/ros/kinetic/lib/python2.7/dist-packages') # append back in order to import rospy
import csv
import os
import tensorflow as tf
from tensorflow.keras import datasets, layers, models
import numpy as np

# Instantiate CvBridge
bridge = CvBridge()
CSV_path = '/home/asus'

def image_callback(msg):

print("Received an image!")
#global model
try:
    model = tf.keras.models.load_model('/home/asus/image_saved/src/models/labDATASET_gen_20E3C2D_cm.model')
    cv2_img = bridge.imgmsg_to_cv2(msg, "bgr8")
    img_array = [(cv2.resize(cv2_img, (240,320)))]
    img_array = np.array(img_array)/255.0
    prediction = model.predict(img_array)
    l = prediction.tolist()
except CvBridgeError as e:
    print(e)

#else:

def main():

with open(os.path.join(CSV_path,'gen.csv'),'a') as f:
    thewriter = csv.writer(f)
    thewriter.writerow(['x'])



rospy.init_node('RGB_image_listener')
# Define your image topic
image_topic = "/camera/rgb/image_raw"
# Set up your subscriber and define its callback
rospy.Subscriber(image_topic, Image, image_callback)
# Spin until ctrl + c
rospy.spin()

if __name__ == '__main__':
    main()

When I run the code I get Aborted (core dumped) or Segmentation fault (core dumped)

whats the write way to do it Please suggest how to fix it

UPDATE1: ok so the error is from this line:

model = tf.keras.models.load_model('/home/asus/image_saved/src/models/labDATASET_gen_20E3C2D_cm.model')
It gives Segmentation fault (core dumped).

whats the correct way to load tf model?

edit retag flag offensive close merge delete

Comments

I would suggest start by cleaning up your code, initialize model in the beginning, and try. Though sounds like you are accessing data that is not there.

Choco93 gravatar image Choco93  ( 2020-07-13 07:58:11 -0500 )edit

i tried that, if i only call the model I get Segmentation fault (core dumped).

arafatsadasd gravatar image arafatsadasd  ( 2020-07-13 12:21:11 -0500 )edit

ok so the error is from this line:

model = tf.keras.models.load_model('/home/asus/image_saved/src/models/labDATASET_gen_20E3C2D_cm.model')

It gives Segmentation fault (core dumped). whats the correct way to load tf model?

arafatsadasd gravatar image arafatsadasd  ( 2020-07-13 13:04:09 -0500 )edit