<jupyter_start><jupyter_text>5: LSTM<jupyter_code>model = Sequential()
model.add(LSTM(128, input_shape=(5, 2)))
model.add(Dense(10))
from keras.utils.layer_utils import print_summary; print_summary(model)
model.compile(loss='mean_squared_error', optimizer='sgd')

model.fit(X_tr, Y_tr, epochs=5)
def gen_traj(model, init, T_i, T_o, T):
    traj = init.reshape(T_i, 2).tolist()    
    for i in range(T):
        seg = model.predict([np.array(traj[i:i+T_o]).flatten().reshape(1, 5, 2)])
        print(seg)
        x = seg.reshape(T_i, 2).tolist()[0]
        traj.append(x)
    return traj
class Dummy(object):
    def predict(self, arr):
        return arr[0] + 1
traj_pred_zero = gen_traj(model, X_t[0], T_i, T_o, 150)
def unzero_traj(traj, i, class_id, is_train=True):
    # find original id from train_test_ids
    id = train_test_ids[class_id]['train'][i] if is_train else train_test_ids[class_id]['test'][i]

    # get the first value from raw traj
    zero = all_trajs_raw[class_id][id][0]

    # reconstruct new raw traj
    unzeroed_traj = traj + zero
    
    return unzeroed_traj
street_raw = imread('/nfs/diskstation/jren/projection_average.png')
street = street_raw[97:719, 510:1132][:,:,:3]
street = resize(street, [1000,1000])
traj_pred = unzero_traj(traj_pred_zero, 0, 7, True)
plt.figure(figsize=(10,10))
plt.imshow(street)
plt.scatter(traj_pred[:,0], traj_pred[:,1])
plt.show()
print(traj_pred)<jupyter_output>[[ 505.29901515  806.45429003]
 [ 504.91038199  803.57837466]
 [ 504.08709739  799.1583139 ]
 [ 503.94756558  798.66521958]
 [ 504.30342145  801.28396643]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.80436718  866.11396379]
 [ 494.8[...]
{'fraction_non_alphanumeric': 0.14644179350061703, 'fraction_numerical': 0.3118058412176059, 'mean_word_length': 4.12, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '476895', 'license': 'MIT', 'n_tokens_mistral': 1565, 'n_tokens_neox': 1040, 'n_words': 173, 'path': 'traffic_modeling/Traffic Modeling Deep Models.ipynb', 'repo_name': 'BerkeleyAutomation/traffic-cam-pipeline', 'size': '2431'}