├── README.md ├── lol_hero.py └── lol_hero_4w ├── checkpoint ├── frozen_inference_graph.pb ├── lol.pbtxt ├── model.ckpt.data-00000-of-00001 ├── model.ckpt.index ├── model.ckpt.meta ├── pipeline.config └── saved_model └── saved_model.pb /README.md: -------------------------------------------------------------------------------- 1 | # lol_auto_attack 2 | LOL自动攻击系统 3 | 配合Tensorflow Object detection API 使用 4 | -------------------------------------------------------------------------------- /lol_hero.py: -------------------------------------------------------------------------------- 1 | import os 2 | os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1' 3 | import time 4 | import pyautogui as pag 5 | start = time.time() 6 | import numpy as np 7 | import os 8 | import six.moves.urllib as urllib 9 | import sys 10 | import tarfile 11 | import threading 12 | import tensorflow as tf 13 | import zipfile 14 | import cv2 15 | import win32gui, win32ui, win32con, win32api 16 | import multiprocessing as mp 17 | from multiprocessing import Process 18 | from PIL import ImageGrab 19 | from collections import defaultdict 20 | from io import StringIO 21 | from matplotlib import pyplot as plt 22 | from PIL import Image 23 | import pandas as pd 24 | if tf.__version__ < '1.4.0': 25 | raise ImportError('Please upgrade your tensorflow installation to v1.4.* or later!') 26 | 27 | os.chdir('F:\\AI\\models-master\\research\\object_detection') 28 | 29 | # Env setup 30 | # This is needed to display the images. 31 | # %matplotlib inline 32 | 33 | # This is needed since the notebook is stored in the object_detection folder. 34 | sys.path.append("..") 35 | 36 | # Object detection imports 37 | from object_detection.utils import visualization_utils as vis_util 38 | from object_detection.utils import label_map_util 39 | # Model preparation 40 | # What model to download. 41 | 42 | # 这是我们刚才训练的模型 43 | MODEL_NAME = 'lol_hero_4w' 44 | 45 | # 对应的Frozen model位置 46 | # Path to frozen detection graph. This is the actual model that is used for the object detection. 47 | PATH_TO_CKPT = MODEL_NAME + '/frozen_inference_graph.pb' 48 | 49 | # List of the strings that is used to add correct label for each box. 50 | PATH_TO_LABELS = os.path.join(MODEL_NAME, 'lol.pbtxt') 51 | 52 | # 改成自己例子中的类别数,2 53 | NUM_CLASSES = 1 54 | 55 | 56 | # Load a (frozen) Tensorflow model into memory. 57 | detection_graph = tf.Graph() 58 | with detection_graph.as_default(): 59 | od_graph_def = tf.GraphDef() 60 | with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid: 61 | serialized_graph = fid.read() 62 | od_graph_def.ParseFromString(serialized_graph) 63 | tf.import_graph_def(od_graph_def, name='') 64 | 65 | # Loading label map 66 | label_map = label_map_util.load_labelmap(PATH_TO_LABELS) 67 | categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, 68 | use_display_name=True) 69 | category_index = label_map_util.create_category_index(categories) 70 | 71 | 72 | # Helper code 73 | def load_image_into_numpy_array(image): 74 | (im_width, im_height) = image.size 75 | return np.array(image.getdata()).reshape( 76 | (im_height, im_width, 3)).astype(np.uint8) 77 | 78 | def shot(): 79 | # global image_np 80 | # while True: 81 | image = ImageGrab.grab() 82 | image_np = np.array(image) 83 | # print("shot111") 84 | return image_np 85 | 86 | 87 | def mouse(min_x,min_y): 88 | # while True: 89 | # if min_x > 0 and min_y > 0: 90 | # pag.click(min_x + 10, min_y + 5, button="right") 91 | 92 | if min_x > 0 and min_y > 0: 93 | pag.click(min_x + 60, min_y +120, button="right") 94 | 95 | 96 | # Detection 97 | 98 | # If you want to test the code with your images, just add path to the images to the TEST_IMAGE_PATHS. 99 | # 测试图片位置 100 | 101 | # PATH_TO_TEST_IMAGES_DIR = os.getcwd() + '\\test_images2' 102 | # os.chdir(PATH_TO_TEST_IMAGES_DIR) 103 | # TEST_IMAGE_PATHS = os.listdir(PATH_TO_TEST_IMAGES_DIR) 104 | # PATH_TO_TEST_IMAGES_DIR = 'A:\\' 105 | # TEST_IMAGE_PATHS = [os.path.join(PATH_TO_TEST_IMAGES_DIR, 'now.jpg')] 106 | # # Size, in inches, of the output images. 107 | # IMAGE_SIZE = (20, 12) 108 | # 109 | # output_path = ('F:\\AI\\Program\\img_lol\\output\\') 110 | # def test(x): 111 | with detection_graph.as_default(): 112 | with tf.Session(graph=detection_graph) as sess: 113 | # Definite input and output Tensors for detection_graph 114 | image_tensor = detection_graph.get_tensor_by_name('image_tensor:0') 115 | # Each box represents a part of the image where a particular object was detected. 116 | detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0') 117 | # Each score represent how level of confidence for each of the objects. 118 | # Score is shown on the result image, together with the class label. 119 | detection_scores = detection_graph.get_tensor_by_name('detection_scores:0') 120 | detection_classes = detection_graph.get_tensor_by_name('detection_classes:0') 121 | num_detections = detection_graph.get_tensor_by_name('num_detections:0') 122 | # TEST_IMAGE_PATHS = os.listdir(os.path.join(image_folder)) 123 | # os.makedirs(output_image_path + image_folder) 124 | # 125 | # image = Image.open(image_path) 126 | # the array based representation of the image will be used later in order to prepare the 127 | # result image with boxes and labels on it. 128 | 129 | # global min_x, min_y 130 | # min_x = 0 131 | # min_y = 0 132 | # shot() 133 | # for t in threads: 134 | # t.setDaemon(True) 135 | # t.start() 136 | for _ in range(0,150): 137 | # def t(): 138 | # global min_x, min_y 139 | # image_np = pool.map(shot, range(1)) 140 | # image = ImageGrab.grab() 141 | # image_np = np.array(image) 142 | 143 | s = time.time() 144 | 145 | 146 | image_np = shot() 147 | 148 | 149 | # image_np = load_image_into_numpy_array(image) 150 | # Expand dimensions since the model expects images to have shape: [1, None, None, 3] 151 | 152 | image_np_expanded = np.expand_dims(image_np, axis=0) 153 | # Actual detection. 154 | 155 | 156 | (boxes, scores, classes, num) = sess.run( 157 | [detection_boxes, detection_scores, detection_classes, num_detections], 158 | feed_dict={image_tensor: image_np_expanded}) 159 | # Visualization of the results of a detection. 160 | vis_util.visualize_boxes_and_labels_on_image_array( 161 | image_np, 162 | np.squeeze(boxes), 163 | np.squeeze(classes).astype(np.int32), 164 | np.squeeze(scores), 165 | category_index, 166 | use_normalized_coordinates=True, 167 | line_thickness=8) 168 | 169 | 170 | e = time.time() 171 | # plt.imshow(image_np) 172 | # 173 | # cv2.imshow(image_np) 174 | # cv2.waitKey(1) 175 | # plt.show() 176 | # for i in range(1,100000): 177 | # a = 1 178 | # plt.close() 179 | s_boxes = boxes[scores > 0.5] 180 | s_classes = classes[scores > 0.5] 181 | # print(s_classes) 182 | # s_scores = scores[scores > 0.5] 183 | width,height = 1920,1080 184 | # screen center : 960,540 185 | # min = 0 186 | min_distance = 1000000000000 187 | 188 | min_x = 0 189 | min_y= 0 190 | distacne = 1000000000 191 | for i in range(len(s_classes)): 192 | if s_classes[i] == 1: 193 | ty = s_boxes[i][0] * height # ymin 194 | tx = s_boxes[i][1] * width # xmin 195 | # print(newdata.iloc[0, 1]) 196 | # print(newdata.iloc[0, 2]) 197 | distacne = (960 - tx) * (960 - tx) + (540 - ty) * (540 - ty) 198 | # 找最小的距离 199 | 200 | if distacne < min_distance and distacne > 50000: 201 | min_distance = distacne 202 | min_x = tx 203 | min_y = ty 204 | 205 | # if min_x > 0 and min_y > 0: 206 | # pag.click(min_x + 10, min_y + 5, button="right") 207 | print(ty,tx) 208 | mouse(min_x,min_y) 209 | # t1 = threading.Thread(target=mouse, args=(min_x,min_y)) 210 | # threads.append(t1) 211 | # t1.setDaemon(True) 212 | # t1.start() 213 | # p.start() 214 | # p = Process(target=mouse, args=(min_x,min_y)) 215 | # p.start() 216 | ee = time.time() 217 | # print("Test: : ", e - s) 218 | # print("click: : ", ee - e) 219 | # print("all : : ", ee - s) 220 | 221 | 222 | # print(min_x,min_y) 223 | # return min_x,min_y 224 | 225 | 226 | 227 | 228 | # threads = [] 229 | # t1 = threading.Thread(target=mouse, args=()) 230 | # threads.append(t1) 231 | # t2 = threading.Thread(target=shot, args=()) 232 | # threads.append(t2) 233 | # t3 = threading.Thread(target=t, args=()) 234 | # threads.append(t3) 235 | 236 | 237 | # if __name__ == '__main__': 238 | 239 | # min_x = 0 240 | # min_y = 0 241 | 242 | # for t in threads: 243 | # t.setDaemon(True) 244 | # t.start() 245 | 246 | 247 | 248 | 249 | 250 | 251 | # if __name__ == '__main__': 252 | # pool = mp.Pool(1) 253 | # pool.map(test, range(1)) 254 | # p = Process(target=mouse) 255 | # test(1) 256 | 257 | 258 | 259 | # def multicore(): 260 | # pool = mp.Pool() 261 | # 262 | # res = pool.map(test, range(2)) 263 | # # print(res) 264 | # 265 | # 266 | # if __name__ == '__main__': 267 | # multicore() 268 | 269 | # if __name__ == '__main__': 270 | # test() 271 | # p = Process(target=shot) 272 | # c = Process(target=mouse) 273 | # p.start() 274 | 275 | # time.sleep(1) 276 | # print('执行主进程的内容了') 277 | 278 | -------------------------------------------------------------------------------- /lol_hero_4w/checkpoint: -------------------------------------------------------------------------------- 1 | model_checkpoint_path: "model.ckpt" 2 | all_model_checkpoint_paths: "model.ckpt" 3 | -------------------------------------------------------------------------------- /lol_hero_4w/frozen_inference_graph.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bend-Function/lol_auto_attack/6e4cc406b2618b9fa6efe24227785d2c728fa693/lol_hero_4w/frozen_inference_graph.pb -------------------------------------------------------------------------------- /lol_hero_4w/lol.pbtxt: -------------------------------------------------------------------------------- 1 | item { 2 | id: 1 3 | name: 'R_blood' 4 | } 5 | item { 6 | id: 2 7 | name: 'B_blood' 8 | } -------------------------------------------------------------------------------- /lol_hero_4w/model.ckpt.data-00000-of-00001: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bend-Function/lol_auto_attack/6e4cc406b2618b9fa6efe24227785d2c728fa693/lol_hero_4w/model.ckpt.data-00000-of-00001 -------------------------------------------------------------------------------- /lol_hero_4w/model.ckpt.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bend-Function/lol_auto_attack/6e4cc406b2618b9fa6efe24227785d2c728fa693/lol_hero_4w/model.ckpt.index -------------------------------------------------------------------------------- /lol_hero_4w/model.ckpt.meta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bend-Function/lol_auto_attack/6e4cc406b2618b9fa6efe24227785d2c728fa693/lol_hero_4w/model.ckpt.meta -------------------------------------------------------------------------------- /lol_hero_4w/pipeline.config: -------------------------------------------------------------------------------- 1 | model { 2 | ssd { 3 | num_classes: 2 4 | image_resizer { 5 | fixed_shape_resizer { 6 | height: 300 7 | width: 300 8 | } 9 | } 10 | feature_extractor { 11 | type: "ssd_mobilenet_v1" 12 | depth_multiplier: 1.0 13 | min_depth: 16 14 | conv_hyperparams { 15 | regularizer { 16 | l2_regularizer { 17 | weight: 3.9999998989515007e-05 18 | } 19 | } 20 | initializer { 21 | truncated_normal_initializer { 22 | mean: 0.0 23 | stddev: 0.029999999329447746 24 | } 25 | } 26 | activation: RELU_6 27 | batch_norm { 28 | decay: 0.9997000098228455 29 | center: true 30 | scale: true 31 | epsilon: 0.0010000000474974513 32 | train: true 33 | } 34 | } 35 | } 36 | box_coder { 37 | faster_rcnn_box_coder { 38 | y_scale: 10.0 39 | x_scale: 10.0 40 | height_scale: 5.0 41 | width_scale: 5.0 42 | } 43 | } 44 | matcher { 45 | argmax_matcher { 46 | matched_threshold: 0.5 47 | unmatched_threshold: 0.5 48 | ignore_thresholds: false 49 | negatives_lower_than_unmatched: true 50 | force_match_for_each_row: true 51 | } 52 | } 53 | similarity_calculator { 54 | iou_similarity { 55 | } 56 | } 57 | box_predictor { 58 | convolutional_box_predictor { 59 | conv_hyperparams { 60 | regularizer { 61 | l2_regularizer { 62 | weight: 3.9999998989515007e-05 63 | } 64 | } 65 | initializer { 66 | truncated_normal_initializer { 67 | mean: 0.0 68 | stddev: 0.029999999329447746 69 | } 70 | } 71 | activation: RELU_6 72 | batch_norm { 73 | decay: 0.9997000098228455 74 | center: true 75 | scale: true 76 | epsilon: 0.0010000000474974513 77 | train: true 78 | } 79 | } 80 | min_depth: 0 81 | max_depth: 0 82 | num_layers_before_predictor: 0 83 | use_dropout: false 84 | dropout_keep_probability: 0.800000011920929 85 | kernel_size: 1 86 | box_code_size: 4 87 | apply_sigmoid_to_scores: false 88 | } 89 | } 90 | anchor_generator { 91 | ssd_anchor_generator { 92 | num_layers: 6 93 | min_scale: 0.20000000298023224 94 | max_scale: 0.949999988079071 95 | aspect_ratios: 1.0 96 | aspect_ratios: 2.0 97 | aspect_ratios: 0.5 98 | aspect_ratios: 3.0 99 | aspect_ratios: 0.33329999446868896 100 | } 101 | } 102 | post_processing { 103 | batch_non_max_suppression { 104 | score_threshold: 9.99999993922529e-09 105 | iou_threshold: 0.6000000238418579 106 | max_detections_per_class: 100 107 | max_total_detections: 100 108 | } 109 | score_converter: SIGMOID 110 | } 111 | normalize_loss_by_num_matches: true 112 | loss { 113 | localization_loss { 114 | weighted_smooth_l1 { 115 | anchorwise_output: true 116 | } 117 | } 118 | classification_loss { 119 | weighted_sigmoid { 120 | anchorwise_output: true 121 | } 122 | } 123 | hard_example_miner { 124 | num_hard_examples: 3000 125 | iou_threshold: 0.9900000095367432 126 | loss_type: CLASSIFICATION 127 | max_negatives_per_positive: 3 128 | min_negatives_per_image: 0 129 | } 130 | classification_weight: 1.0 131 | localization_weight: 1.0 132 | } 133 | } 134 | } 135 | train_config { 136 | batch_size: 3 137 | data_augmentation_options { 138 | random_horizontal_flip { 139 | } 140 | } 141 | data_augmentation_options { 142 | ssd_random_crop { 143 | } 144 | } 145 | optimizer { 146 | rms_prop_optimizer { 147 | learning_rate { 148 | exponential_decay_learning_rate { 149 | initial_learning_rate: 0.004000000189989805 150 | decay_steps: 800720 151 | decay_factor: 0.949999988079071 152 | } 153 | } 154 | momentum_optimizer_value: 0.8999999761581421 155 | decay: 0.8999999761581421 156 | epsilon: 1.0 157 | } 158 | } 159 | num_steps: 200000 160 | } 161 | train_input_reader { 162 | label_map_path: "data/lol.pbtxt" 163 | tf_record_input_reader { 164 | input_path: "data/train.record" 165 | } 166 | } 167 | eval_config { 168 | num_examples: 4 169 | max_evals: 10 170 | use_moving_averages: false 171 | } 172 | eval_input_reader { 173 | label_map_path: "data/lol.pbtxt" 174 | shuffle: false 175 | num_epochs: 1 176 | num_readers: 1 177 | tf_record_input_reader { 178 | input_path: "data/test.record" 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /lol_hero_4w/saved_model/saved_model.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bend-Function/lol_auto_attack/6e4cc406b2618b9fa6efe24227785d2c728fa693/lol_hero_4w/saved_model/saved_model.pb --------------------------------------------------------------------------------