Skip to content

Instantly share code, notes, and snippets.

View pythonlessons's full-sized avatar
🏠
Working from home

Rokas Liuberskis pythonlessons

🏠
Working from home
View GitHub Profile
@pythonlessons
pythonlessons / getwindowgeometry.py
Created October 1, 2020 13:26
YOLO_aimbot_main
def getwindowgeometry():
while True:
output = subprocess.getstatusoutput(f'xdotool search --name Counter-Strike getwindowgeometry')
if output[0] == 0:
t1 = time.time()
LIST = output[1].split("\n")
Window = LIST[0][7:]
Position = LIST[1][12:-12]
x, y = Position.split(",")
x, y = int(x), int(y)
while True:
t1 = time.time()
img = np.array(sct.grab({"top": y-30, "left": x, "width": w, "height": h, "mon": -1}))
img = cv2.cvtColor(img, cv2.COLOR_RGBA2RGB)
image, detection_list, bboxes = detect_enemy(yolo, np.copy(img), input_size=YOLO_INPUT_SIZE, CLASSES=TRAIN_CLASSES, rectangle_colors=(255,0,0))
cv2.circle(image,(int(w/2),int(h/2)), 3, (255,255,255), -1) # center of weapon sight
th_list, t_list = [], []
for detection in detection_list:
diff_x = (int(w/2) - int(detection[1]))*-1
@pythonlessons
pythonlessons / LunarLander-v2_random.py
Created November 10, 2020 11:17
LunarLander-v2_random
import gym
import random
env = gym.make("LunarLander-v2")
def Random_games():
# Each of this episode is its own game.
for episode in range(10):
env.reset()
# this is each frame, up to 500...but we wont make it that far with random.
@pythonlessons
pythonlessons / LunarLander-v2_actor_discrete.py
Created November 10, 2020 13:15
LunarLander-v2_actor_discrete
class Actor_Model:
def __init__(self, input_shape, action_space, lr, optimizer):
X_input = Input(input_shape)
self.action_space = action_space
X = Dense(512, activation="relu", kernel_initializer=tf.random_normal_initializer(stddev=0.01))(X_input)
X = Dense(256, activation="relu", kernel_initializer=tf.random_normal_initializer(stddev=0.01))(X)
X = Dense(64, activation="relu", kernel_initializer=tf.random_normal_initializer(stddev=0.01))(X)
output = Dense(self.action_space, activation="softmax")(X)
@pythonlessons
pythonlessons / LunarLander-v2_critic.py
Last active November 10, 2020 20:17
LunarLander-v2_critic
class Critic_Model:
def __init__(self, input_shape, action_space, lr, optimizer):
X_input = Input(input_shape)
old_values = Input(shape=(1,))
V = Dense(512, activation="relu", kernel_initializer='he_uniform')(X_input)
V = Dense(256, activation="relu", kernel_initializer='he_uniform')(V)
V = Dense(64, activation="relu", kernel_initializer='he_uniform')(V)
value = Dense(1, activation=None)(V)
@pythonlessons
pythonlessons / get_gaes.py
Created November 10, 2020 14:57
get_gaes
def get_gaes(self, rewards, dones, values, next_values, gamma = 0.99, lamda = 0.9, normalize=True):
deltas = [r + gamma * (1 - d) * nv - v for r, d, nv, v in zip(rewards, dones, next_values, values)]
deltas = np.stack(deltas)
gaes = copy.deepcopy(deltas)
for t in reversed(range(len(deltas) - 1)):
gaes[t] = gaes[t] + (1 - dones[t]) * gamma * lamda * gaes[t + 1]
target = gaes + values
if normalize:
gaes = (gaes - gaes.mean()) / (gaes.std() + 1e-8)
@pythonlessons
pythonlessons / LunarLander-v2-replay.py
Last active November 13, 2020 06:39
LunarLander-v2-replay
def replay(self, states, actions, rewards, predictions, dones, next_states):
# reshape memory to appropriate shape for training
states = np.vstack(states)
next_states = np.vstack(next_states)
actions = np.vstack(actions)
predictions = np.vstack(predictions)
# Get Critic network predictions
values = self.Critic.predict(states)
next_values = self.Critic.predict(next_states)
@pythonlessons
pythonlessons / LunarLander-v2-run_batch.py
Last active November 13, 2020 06:46
LunarLander-v2-run_batch
def run_batch(self): # train every self.Training_batch episodes
state = self.env.reset()
state = np.reshape(state, [1, self.state_size[0]])
done, score, SAVING = False, 0, ''
while True:
# Instantiate or reset games memory
states, next_states, actions, rewards, predictions, dones = [], [], [], [], [], []
for t in range(self.Training_batch):
self.env.render()
# Actor picks an action
@pythonlessons
pythonlessons / BipedalWalker-v3_random.py
Created November 18, 2020 13:50
BipedalWalker-v3_random
import gym
import random
import numpy as np
env = gym.make("BipedalWalker-v3")
def Random_games():
# Each of this episode is its own game.
action_size = env.action_space.shape[0]
for episode in range(10):
@pythonlessons
pythonlessons / BipedalWalker-v3_continuous_actor.py
Created November 18, 2020 17:52
BipedalWalker-v3_continuous_actor
class Actor_Model:
def __init__(self, input_shape, action_space, lr, optimizer):
X_input = Input(input_shape)
self.action_space = action_space
X = Dense(512, activation="relu", kernel_initializer=tf.random_normal_initializer(stddev=0.01))(X_input)
X = Dense(256, activation="relu", kernel_initializer=tf.random_normal_initializer(stddev=0.01))(X)
X = Dense(64, activation="relu", kernel_initializer=tf.random_normal_initializer(stddev=0.01))(X)
output = Dense(self.action_space, activation="tanh")(X)