Skip to content

Instantly share code, notes, and snippets.

@rpicatoste
rpicatoste / test_dataframe.py
Created October 19, 2018 09:18
Testing dataframe with extra attributes
import pandas as pd
class MyDF(pd.DataFrame):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.definition = 'my_definition'
my_df = MyDF()
my_df.__dict__ = df.__dict__.copy()
print(len(my_df))
print(my_df.definition)
@rpicatoste
rpicatoste / convert_to_inference_model.py
Last active October 28, 2022 09:40
Function to convert a Keras LSTM model trained as stateless to a stateful model expecting a single sample and time step as input to use in inference.
import json
from keras.models import model_from_json
def convert_to_inference_model(original_model):
original_model_json = original_model.to_json()
inference_model_dict = json.loads(original_model_json)
layers = inference_model_dict['config']
for layer in layers:
if 'stateful' in layer['config']:
tch_size += direction
if training_config.batch_size < 1:
direction *= -1
previous_epoch_time = current_epoch_time
file_name = 'model_epoch_{:04}.h5'.format(epoch)
history_file_name = 'model_history.pickle'
try:
if 'linux' in sys
@rpicatoste
rpicatoste / fly.py
Created March 20, 2018 17:58
Example of the quadcopter flying
# %%
import csv
import numpy as np
from task import Task
from agents.agent import DDPG
from plot_functions import plot_results
from collections import defaultdict
import copy
import matplotlib.pyplot as plt
from pid import PID
from lowpass import LowPassFilter
from yaw_controller import YawController
import rospy
import pickle
import copy
import os
controller_log_time_seconds = 5
controller_log_file_base = '/home/student/shared_vm/controller_id_log_'
#%%
import pickle
import numpy as np
import matplotlib.pyplot as plt
server_log_filename = 'C:\workspace\shared_vm\server_pid_log_0.pkl'
with open(server_log_filename, 'rb') as f:
log = pickle.load(f)