Пример #1
0
    def centroid_within_bounds(self, centroid, objects, thresh=0.2):
        # check if new centroid is within bounds of previously noted ones
        for object in objects:
            if  Util.within_threshold(centroid.x, object.centroid.x) and Util.within_threshold(centroid.y, object.centroid.y):
                    return True

        return False
Пример #2
0
    def execute(self, userdata):
        # go to a specified location where the user is at
        approach_user_point = self.ogm.approach_user(self.tiago.user_point)
        self.tiago.approach_user_point = approach_user_point

        # go to approach point, orientation will be off
        self.tiago.goto_location(
            Pose(approach_user_point,
                 Util.quaternion_at_point(approach_user_point)))
        # orient to face table user point
        self.tiago.goto_location(
            Util.turn_towards_point(
                Point(self.tiago.user_point.x, self.tiago.user_point.y, 0.0)))

        self.tiago.talk('Hello, what would you like me to do ?')

        search_n_fetch_queries = self.extract_tasks_with_dialogue()

        if len(search_n_fetch_queries):
            print(search_n_fetch_queries)
            rospy.set_param('/search_n_fetch_queries', search_n_fetch_queries)
            self.tiago.talk('I will be right back, with your requests.')
            return 'start_done'
        else:
            self.tiago.talk(
                'I did not get any requests from you. I will go back to sleep now.'
            )
            return 'start_abort'
Пример #3
0
 def go_to_user_location(self):
     # go to approach point, orientation will be off
     self.tiago.goto_location(
         Pose(self.tiago.approach_user_point,
              Util.quaternion_at_point(self.tiago.approach_user_point)))
     # orient to face table user point
     self.tiago.goto_location(
         Util.turn_towards_point(
             Point(self.tiago.user_point.x, self.tiago.user_point.y, 0.0)))
Пример #4
0
    def approach_object(self, current_furniture, object):
        # calculate object approach point and navigate to it
        approach_object_point = self.ogm.approach_object(
            current_furniture, object)
        self.tiago.goto_location(
            Pose(approach_object_point,
                 Util.quaternion_at_point(approach_object_point)))

        # orient to face object
        self.tiago.goto_location(Util.turn_towards_point(object.centroid))
    def grasp_object(self, pnp_goal):
        self.clear_world_objects()
        rospy.loginfo("adding new 'part' object")
        self.scene.add_box('part', pnp_goal.object_pose,
                           (pnp_goal.object_depth, pnp_goal.object_width,
                            pnp_goal.object_height))

        # wait for objects part to appear
        self.wait_for_planning_scene_object('part')

        # compute grasp
        grasps = self.generate_grasps(pnp_goal)
        rospy.loginfo('computed grasps :: ')
        rospy.loginfo(grasps)
        error_code = -1

        for grasp in grasps:
            # publish grasp marker
            print('publishing grasp marker! ' + grasp.id)
            if grasp.id.split('_')[0] != 'front':
                grasp_marker = Util.visualize_marker(grasp.grasp_pose.pose,
                                                     scale=0.02,
                                                     type='pose',
                                                     color='blue')
            else:
                grasp_marker = Util.visualize_marker(grasp.grasp_pose.pose,
                                                     scale=0.02,
                                                     type='pose')

            self.grasp_marker_pub.publish(grasp_marker)

            goal = create_pickup_goal('arm_torso', 'part',
                                      pnp_goal.object_pose, [grasp],
                                      self.links_to_allow_contact)
            rospy.loginfo('sending pick goal')
            self.pickup_ac.send_goal(goal)
            rospy.loginfo('waiting for result')
            self.pickup_ac.wait_for_result()

            result = self.pickup_ac.get_result()
            error_code = result.error_code.val
            rospy.logdebug('using torso result: ' + str(result))
            rospy.loginfo('pick result: ' + str(moveit_error_dict[error_code]))

            if error_code == 1:
                # turn around for about 180 degs to be clear of furniture
                for i in range(85):
                    self.move((0, 0, 0), (0, 0, 0.4))
                    self.rate.sleep()

                # move arm close to body after grasp is successful
                self.execute_post_grasp_goal(grasp)
                break

        return error_code
Пример #6
0
	def deploy_antivirus_application(cls):
		gui = Task("GUI", Util.generate_random_cpu_cycles(), 1, Util.generate_random_input_data(), Util.generate_random_output_data(), False)
		load_library = Task("LOAD_LIBRARY", Util.generate_di_cpu_cycles(), 1, Util.generate_di_input_data(), Util.generate_di_output_data(), True)
		scan_file = Task("SCAN_FILE", Util.generate_di_cpu_cycles(), 2, Util.generate_di_input_data(), Util.generate_di_output_data(), True)
		compare = Task("COMPARE", Util.generate_di_cpu_cycles(), 1, Util.generate_di_input_data(), Util.generate_di_output_data(), True)
		output = Task("OUTPUT", Util.generate_random_cpu_cycles(), 1, Util.generate_random_input_data(), Util.generate_random_output_data(), False)

		antivirus_delay_dict = {
			gui: [(load_library, num.randint(2, 10)), (scan_file, num.randint(2, 10))],
			load_library: [(compare, num.randint(2, 10))],
			scan_file: [(compare, num.randint(2, 10))],
			compare: [(output, num.randint(2, 10))],
			output: []
		}

		cls._mobile_app = MobileApplication(ANTIVIRUS, antivirus_delay_dict)
Пример #7
0
    def dimensions_within_bounds(self, object, filtered_object, threshold=0.2):
        # check if object dimensions in new frame is within bounds of previously recorded dimensions in a diff frame
        print('checking for dimensions : ')
        if Util.within_threshold(
                object.width, filtered_object.width,
                threshold=threshold) and Util.within_threshold(
                    object.height, filtered_object.height,
                    threshold=threshold) and Util.within_threshold(
                        object.depth,
                        filtered_object.depth,
                        threshold=threshold):
            print(object)
            print(filtered_object)
            return True

        return False
Пример #8
0
def loadData():
    '''
    This function loads the data from various data files and does the basic preprocessing.
    Created to leverage the power of streamlit cache.
    '''
    movies_df = Preprocess.loadFile("movies")
    ratings_df = Preprocess.loadFile("ratings")
    final_vector_df = Util.loadObj('final_vector_df')
    embeddings_matrix = final_vector_df.loc[:, final_vector_df.
                                            columns != 'movieId']
    embedding_movie_list = final_vector_df['movieId'].tolist()

    ratings_df2 = Preprocess.loadFile("ratings")
    # ratings_input =  [ratings_df['userId'].to_numpy(), ratings_df['movieId'].to_numpy(), ratings_df['rating'].to_numpy()]
    users = list(set(ratings_df['userId'].tolist()))
    movies = list(set(ratings_df['movieId'].tolist()))

    users_dict = {u: i for i, u in enumerate(users)}
    movies_dict = {m: i for i, m in enumerate(movies)}  # Movie Id to Idx
    movies_idx_dict = {i: m for i, m in enumerate(movies)}  #Idx to movie Id

    ratings_df2['userId'] = ratings_df2['userId'].apply(
        lambda x: users_dict[x])
    ratings_df2['movieId'] = ratings_df2['movieId'].apply(
        lambda x: movies_dict[x])

    return movies_df, ratings_df, final_vector_df, embeddings_matrix, embedding_movie_list, ratings_df2, users, movies, users_dict, movies_dict, movies_idx_dict
Пример #9
0
    def execute(self, userdata):
        # get search and fetch params
        search_n_fetch_queries = rospy.get_param('/search_n_fetch_queries')

        for index in range(0, len(self.tiago.furniture)):
            current_furniture = self.tiago.furniture[index]
            current_furniture['objects'] = []
            rospy.loginfo('Going to furniture %s' % current_furniture['name'])

            # initial approach to nearest free spot. orientation will be wrong
            approach_point = self.ogm.approach_furniture(current_furniture)
            self.tiago.goto_location(Pose(approach_point, Util.quaternion_at_point(approach_point)))

            # orient to face table center
            self.tiago.goto_location(Util.turn_towards_point(Point(approach_point.x, current_furniture['top_right'].y, 0.0)))

            self.tiago.talk('I am about to scan this furniture for objects.')

            self.tiago.play('lower_head')
            self.look_for_objects(current_furniture)

            center_y = (current_furniture['bottom_left'].y + current_furniture['top_right'].y)/2
            # turn head to cover left and right areas of the furniture
            current_pose = self.tiago.get_robot_pose()
            self.tiago.look_at(Util.map_to_base(Point(current_furniture['top_left'].x, center_y, 0.0), current_pose))
            self.look_for_objects(current_furniture)

            self.tiago.look_at(Util.map_to_base(Point(current_furniture['top_right'].x, center_y, 0.0), current_pose))
            self.look_for_objects(current_furniture)
            # reset head back to normal
            self.tiago.play('lower_head')

            if len(current_furniture['objects']):
                search_n_fetch_queries, requests = Util.create_snf_requests(current_furniture['objects'], search_n_fetch_queries, current_furniture)
                self.search_n_fetch_requests.extend(requests)

            # exit explore loop when queries are over
            if not len(search_n_fetch_queries):
                break

        rospy.set_param('/search_n_fetch_queries', search_n_fetch_queries)
        self.tiago.snf_requests = self.search_n_fetch_requests
        # transition to pick object or go back to user directly
        if len(filter(lambda q: q['intent'] == 'fetch', self.tiago.snf_requests)):    # if there are fetch queries
            return 'manipulate_object'
        else:
            return 'report_back'    # only search queries to report about
Пример #10
0
	def deploy_chess_application(cls):
		gui = Task("GUI", Util.generate_random_cpu_cycles(), 1, Util.generate_random_input_data(), Util.generate_random_output_data(), False)
		update_chess = Task("UPDATE_CHESS", Util.generate_random_cpu_cycles(), 1, Util.generate_random_input_data(), Util.generate_random_output_data(), True)
		compute_move = Task("COMPUTE_MOVE", Util.generate_ci_cpu_cycles(), 2, Util.generate_ci_input_data(), Util.generate_ci_output_data(), True)
		output = Task("OUTPUT", Util.generate_random_cpu_cycles(), 1, Util.generate_random_input_data(), Util.generate_random_output_data(), False)

		chess_delay_dict = {
			gui: [(update_chess, num.randint(2, 10))],
			update_chess: [(compute_move, num.randint(2, 10))],
			compute_move: [(output, num.randint(2, 10))],
			output: []
		}

		cls._mobile_app = MobileApplication(CHESS, chess_delay_dict)
Пример #11
0
## combining the genre tags and the user tags
movies2_df = movies2_df.merge(grouped_df, on='movieId', how='left')
movies2_df['tag'] = movies2_df['tag'].apply(
    lambda x: str(x)) + ' ' + movies2_df['genres']
movies2_df['tag'] = movies2_df['tag'].apply(
    lambda x: x.replace('nan', '').strip())
tags_grouped_df = movies2_df.iloc[:][['movieId', 'tag']]
print(tags_grouped_df.head())
print(tags_grouped_df.shape)

## calculating the TFIDF matrix
tfidf_df = Preprocess.createTFIDFMatrix(tags_grouped_df)
print(tfidf_df.shape)

## dumping the tfidf matrix
Util.saveObj(tfidf_df, 'tfidf_df')

# ## loading the TFIDF matrix
# tfidf_df =  Util.loadObj('tfidf_df')
# print(tfidf_df.shape)

## loading the reduced TFIDF matrix
tfidf_reduced_df = Util.loadObj('tfidf_reduced_df')
print(tfidf_reduced_df.shape)

## creating vector df with spacy sentence vector
vector_df = createSentenceVector(imdb_df)
print(vector_df.shape)

## dumping the vector df
Util.saveObj(vector_df, 'vector_df')
Пример #12
0
    def call(self, input):
        encoder_out_1 = self.dropout_layer(self.EncoderDense1(input))
        encoder_out_2 = self.dropout_layer(self.EncoderDense2(encoder_out_1))
        bottleneck_out = self.dropout_layer(
            self.BottleNeckDense(encoder_out_2))
        decoder_out_1 = self.dropout_layer(self.DecoderDense1(bottleneck_out))
        decoder_out_2 = self.dropout_layer(self.DecoderDense2(decoder_out_1))
        final_out = self.dropout_layer(self.FinalDense(decoder_out_2))
        return final_out


NUM_EPOCHS = 100
BATCH_SIZE = 64

tfidf_matrix = Util.loadObj('tfidf_df')
X = tfidf_matrix.to_numpy()
features = X.shape[1]

model = AutoEncoder(features)
optimizer = keras.optimizers.Adam(lr=0.000003)
loss = lambda x, x_hat: tf.reduce_sum(keras.losses.mean_squared_error(
    x, x_hat))

model.compile(loss=loss, optimizer=optimizer, metrics=['mse'])
model.fit(x=X, y=X, batch_size=BATCH_SIZE, epochs=NUM_EPOCHS)

reduced = model.BottleNeckDense(model.EncoderDense2(model.EncoderDense1(X)))

reduced_np = reduced.numpy()
indices = tfidf_matrix.index.tolist()
Пример #13
0
	def deploy_network_model(cls):
		cloud_dc = cls.__get_cloud_dc_server()
		edge_db_server = cls.__get_edge_database_server('A')
		edge_comp_server = cls.__get_edge_computational_server('A')
		edge_reg_server = cls.__get_edge_regular_server('A')
		mobile_device = cls

		# network bandwidth is hardcoded but network latency contains randomness feature in the distribuiton for every method invocation
		# thus network latency method will be invoked only once for bidirectional connections to gain symmetric latency distribuiton 

		# Cloud DC <-> Edge database server
		cloud_dc__edge_db_server__net_lat = Util.get_network_latency(cloud_dc, edge_db_server)

		# Cloud DC <-> Edge computational intensive server
		cloud_dc__edge_comp_server__net_lat = Util.get_network_latency(cloud_dc, edge_comp_server)

		# Cloud DC <-> Edge regular server
		cloud_dc__edge_reg_server__net_lat = Util.get_network_latency(cloud_dc, edge_reg_server)

		# Cloud DC <-> mobile device
		cloud_dc__mobile_device__net_lat = Util.get_network_latency(cloud_dc, mobile_device)

		# Edge database server <-> Edge computational intensive server
		edge_db_server__edge_comp_server__net_lat = Util.get_network_latency(edge_db_server, edge_comp_server)

		# Edge database server <-> Edge regular server
		edge_db_server__edge_reg_server__net_lat = Util.get_network_latency(edge_db_server, edge_reg_server)

		# Edge database server <-> mobile device
		edge_db_server__mobile_device__net_lat = Util.get_network_latency(edge_db_server, mobile_device)

		# Edge computational intensive server <-> Edge regular server
		edge_comp_server__edge_reg_server__net_lat = Util.get_network_latency(edge_comp_server, edge_reg_server)

		# Edge computational intensive server <-> mobile device
		edge_comp_server__mobile_device__net_lat = Util.get_network_latency(edge_comp_server, mobile_device)

		# Edge regular server <-> mobile device
		edge_reg_server__mobild_device__net_lat = Util.get_network_latency(edge_reg_server, mobile_device)


		cls._network = {
			cloud_dc.get_name(): [(edge_db_server.get_name(), cloud_dc__edge_db_server__net_lat, Util.get_network_bandwidth(cloud_dc, edge_db_server)),
				(edge_comp_server.get_name(), cloud_dc__edge_comp_server__net_lat, Util.get_network_bandwidth(cloud_dc, edge_comp_server)),
				(edge_reg_server.get_name(), cloud_dc__edge_reg_server__net_lat, Util.get_network_bandwidth(cloud_dc, edge_reg_server)),
				(mobile_device.get_name(), cloud_dc__mobile_device__net_lat, Util.get_network_bandwidth(cloud_dc, mobile_device))],
			edge_db_server.get_name(): [(cloud_dc.get_name(), cloud_dc__edge_db_server__net_lat, Util.get_network_bandwidth(edge_db_server, cloud_dc)),
				(edge_comp_server.get_name(), edge_db_server__edge_comp_server__net_lat, Util.get_network_bandwidth(edge_db_server, edge_comp_server)),
				(edge_reg_server.get_name(), edge_db_server__edge_reg_server__net_lat, Util.get_network_bandwidth(edge_db_server, edge_reg_server)),
				(mobile_device.get_name(), edge_db_server__mobile_device__net_lat, Util.get_network_bandwidth(edge_db_server, mobile_device))],
			edge_comp_server.get_name(): [(cloud_dc.get_name(), cloud_dc__edge_comp_server__net_lat, Util.get_network_bandwidth(edge_comp_server, cloud_dc)),
				(edge_db_server.get_name(), edge_db_server__edge_comp_server__net_lat, Util.get_network_bandwidth(edge_comp_server, edge_db_server)),
				(edge_reg_server.get_name(), edge_comp_server__edge_reg_server__net_lat, Util.get_network_bandwidth(edge_comp_server, edge_reg_server)),
				(mobile_device.get_name(), edge_comp_server__mobile_device__net_lat, Util.get_network_bandwidth(edge_comp_server, mobile_device))],
			edge_reg_server.get_name(): [(cloud_dc.get_name(), cloud_dc__edge_reg_server__net_lat, Util.get_network_bandwidth(edge_reg_server, cloud_dc)),
				(edge_db_server.get_name(), edge_db_server__edge_reg_server__net_lat, Util.get_network_bandwidth(edge_reg_server, edge_db_server)),
				(edge_comp_server.get_name(), edge_comp_server__edge_reg_server__net_lat, Util.get_network_bandwidth(edge_reg_server, edge_comp_server)),
				(mobile_device.get_name(), edge_reg_server__mobild_device__net_lat, Util.get_network_bandwidth(edge_reg_server, mobile_device))],
			mobile_device.get_name(): [(cloud_dc.get_name(), cloud_dc__mobile_device__net_lat, Util.get_network_bandwidth(mobile_device, cloud_dc)),
				(edge_db_server.get_name(), edge_db_server__mobile_device__net_lat, Util.get_network_bandwidth(mobile_device, edge_db_server)),
				(edge_comp_server.get_name(), edge_comp_server__mobile_device__net_lat, Util.get_network_bandwidth(mobile_device, edge_comp_server)),
				(edge_reg_server.get_name(), edge_reg_server__mobild_device__net_lat, Util.get_network_bandwidth(mobile_device, edge_reg_server))]
		}
Пример #14
0
	def deploy_gps_navigator_application(cls):
		conf_panel = Task("CONF_PANEL", Util.generate_random_cpu_cycles(), 1, Util.generate_random_input_data(), Util.generate_random_output_data(), False)
		gps = Task("GPS", Util.generate_random_cpu_cycles(), 3, Util.generate_random_input_data(), Util.generate_random_output_data(), False)
		control = Task("CONTROL", Util.generate_ci_cpu_cycles(), 5, Util.generate_ci_input_data(), Util.generate_ci_output_data(), True)
		maps = Task("MAPS", Util.generate_di_cpu_cycles(), 5, Util.generate_di_input_data(), Util.generate_di_output_data(), True)
		path_calc = Task("PATH_CALC", Util.generate_di_cpu_cycles(), 2, Util.generate_di_input_data(), Util.generate_di_output_data(), True)
		traffic = Task("TRAFFIC", Util.generate_di_cpu_cycles(), 1, Util.generate_di_input_data(), Util.generate_di_output_data(), True)
		voice_synth = Task("VOICE_SYNTH", Util.generate_random_cpu_cycles(), 1, Util.generate_random_input_data(), Util.generate_random_output_data(), False)
		gui = Task("GUI", Util.generate_random_cpu_cycles(), 1, Util.generate_random_input_data(), Util.generate_random_output_data(), False)
		speed_trap = Task("SPEED_TRAP", Util.generate_random_cpu_cycles(), 1, Util.generate_random_input_data(), Util.generate_random_output_data(), False)

		gps_navigator_delay_dict = {
			conf_panel: [(control, num.randint(2, 10))],
			gps: [(control, num.randint(2, 10))],
			control: [(maps, num.randint(2, 10)), (path_calc, num.randint(2, 10)), (traffic, num.randint(2, 10))],
			maps: [(path_calc, num.randint(2, 10))],
			traffic: [(path_calc, num.randint(2, 10))],
			path_calc: [(voice_synth, num.randint(2, 10)), (gui, num.randint(2, 10)), (speed_trap, num.randint(2, 10))],
			voice_synth: [],
			gui: [],
			speed_trap: []
		}

		cls._mobile_app = MobileApplication(GPS_NAVIGATOR, gps_navigator_delay_dict)
Пример #15
0
	def deploy_facerecognizer_application(cls):
		gui = Task("GUI", Util.generate_di_cpu_cycles(), 1, Util.generate_di_input_data(), Util.generate_di_output_data(), False)
		find_match = Task("FIND_MATCH", Util.generate_di_cpu_cycles(), 1, Util.generate_di_input_data(), Util.generate_di_output_data(), True)
		init = Task("INIT", Util.generate_di_cpu_cycles(), 2, Util.generate_di_input_data(), Util.generate_di_output_data(), True)
		detect_face = Task("DETECT_FACE", Util.generate_di_cpu_cycles(), 1, Util.generate_di_input_data(), Util.generate_di_output_data(), True)
		output = Task("OUTPUT", Util.generate_di_cpu_cycles(), 1, Util.generate_di_input_data(), Util.generate_di_output_data(), False)

		facerecognizer_delay_dict = {
			gui: [(find_match, num.randint(2, 10))],
			find_match: [(init, num.randint(2, 10)), (detect_face, num.randint(2, 10))],
			init: [(detect_face, num.randint(2, 10))],
			detect_face: [(output, num.randint(2, 10))],
			output: []
		}

		cls._mobile_app = MobileApplication(FACERECOGNIZER, facerecognizer_delay_dict)
Пример #16
0
	def deploy_facebook_application(cls):
		# parameters are (name, millions of instructions, memory (Gb), input data (kb), output data (kb), offloadability)
		facebook_gui = Task("FACEBOOK_GUI", Util.generate_random_cpu_cycles(), 1, Util.generate_random_input_data(), Util.generate_random_output_data(), False)
		get_token = Task("GET_TOKEN", Util.generate_random_cpu_cycles(), 1, Util.generate_random_input_data(), Util.generate_random_output_data(), True)
		post_request = Task("POST_REQUEST", Util.generate_random_cpu_cycles(), 2, Util.generate_random_input_data(), Util.generate_random_output_data(), True)
		process_response = Task("PROCES_RESPONSE", Util.generate_random_cpu_cycles(), 2, Util.generate_random_input_data(), Util.generate_random_output_data(), True)
		file_upload = Task("FILE_UPLOAD", Util.generate_di_cpu_cycles(), 2, Util.generate_di_input_data(), Util.generate_di_output_data(), False)
		apply_filter = Task("APPLY_FILTER", Util.generate_di_cpu_cycles(), 2, Util.generate_di_input_data(), Util.generate_di_output_data(), True)
		facebook_post = Task("FACEBOOK_POST", Util.generate_di_cpu_cycles(), 2, Util.generate_di_input_data(), Util.generate_di_output_data(), False)
		output = Task("OUTPUT", Util.generate_random_cpu_cycles(), 1, Util.generate_random_input_data(), Util.generate_random_output_data(), False)

		facebook_delay_dict = {
			facebook_gui: [(get_token, num.randint(2, 10)), (post_request, num.randint(2, 10))],
			get_token: [(post_request, num.randint(2, 10))],
			post_request: [(process_response, num.randint(2, 10))],
			process_response: [(file_upload, num.randint(2, 10))],
			file_upload: [(apply_filter, num.randint(2, 10))],
			apply_filter: [(facebook_post, num.randint(2, 10))],
			facebook_post: [(output, num.randint(2, 10))],
			output: []
		}

		cls._mobile_app = MobileApplication(FACEBOOK, facebook_delay_dict)
Пример #17
0
'/', 'Index',
'/extractor', 'FileHandler', # For uploading a file
'/extractor/file', 'PDFStreamHandler', # For uploading any binary data stream
'/extractor/(.+)/(header|citations|body|text|file|keyphrases)', 'Extractor', # For retrieving file information
'/extractor/(.+)', 'FileHandler', # For deleting a file

)

ROOT_FOLDER="../" # there must be a trailing /
TMP_FOLDER=tempfile.gettempdir()+"/citeseerextractor/" #Specifies temp folder - useful for cleaning up afterwards

cgi.maxlen = 5 * 1024 * 1024 # 5MB file size limit for uploads

global utilities
utilities = Util()
	
class Index:
	"""Loads the index page from the static dir"""
	def GET(self):
		web.header('Content-Type','text/html; charset=utf-8') 	
		raise web.seeother('/static/index.html')
		
class Extractor:
	
	def GET(self, datafile, method):
		
		params = web.input(output="xml")
		"""Returns some extracted information from a file"""
		extractor = Extraction()
		data = ''