Exemplo n.º 1
0
 def __get_text(self, chapter_start_url, book_name, topic):
     '''
     小说正文爬取并写入磁盘
     :param chapter_start_url:
     :param book_name:
     :param topic:
     :return:
     '''
     # 文章正文部分是js 用selenium模拟浏览器获取html页面
     driver = dr()
     driver.get(chapter_start_url)
     # 网络时整个页面没有加载外全会导致抓取内容错误
     # 直接调用sheep对整个线程不安全 故采用 ▲t1-▲t2的方式拖延程序
     start_time = int(time.time())
     while True:
         end_time = int(time.time())
         if end_time - start_time >= 1:
             break
     soup = BeautifulSoup(driver.page_source, "html5lib")
     ps = soup.select("#chapter-content p")
     text_list = [
         "{0}\n".format(p.string.encode("utf-8")) for p in ps if p.string
     ]
     driver.quit()
     io = IO()
     io.write(text_list, book_name, topic)
     logging.info(
         "--------------------{0}{1} ..下载完成--------------------".format(
             book_name.encode("utf-8"), topic))
Exemplo n.º 2
0
 def __init__(self, number_of_epochs=1000, content_weight=1e3, style_weight=1e-2, model_name="mobilenetv2_coco_voctrainaug", enable_gpu=False, verbose=False):
     self.number_of_epochs = number_of_epochs
     self.content_weight = content_weight
     self.style_weight = style_weight
     self.content_layers = ["block5_conv2"]
     self.style_layers = ["block1_conv1", "block2_conv1", "block3_conv1", "block4_conv1", "block5_conv1"]
     self.model_name = model_name
     self.verbose = verbose
     self.enable_gpu = enable_gpu
     self._set_device()
     tf.compat.v1.enable_eager_execution()
     self.path = IO()
     if(self.verbose == True):
         print ("Eager Execution: {}".format(tf.executing_eagerly()))
Exemplo n.º 3
0
parser.add_argument('--MUTPB', type=float, default=0.1)
parser.add_argument('--gain_max', type=float, default=2.0)
parser.add_argument('--speed_max', type=float, default=2.0)
args = parser.parse_args()

env_name = args.env_name
env = gym.make(env_name)
log_name = 'PSO4_open'

# Set the logging variables
# This also creates a new log file
# Create log files
log_dir = configure_log_dir(env_name, txt=log_name, No_time=False)
logging_output(log_dir)
logger = LoggerCsv(log_dir, csvname='log_results')
results_IO = IO(os.path.join(log_dir, 'results.pkl'))
args_IO = IO(os.path.join(log_dir, 'args.pkl')).to_pickle(args)


def parmeter_generate(pmin, pmax):
    parm_list = [random.uniform(pmin, pmax) for _ in range(27)]

    return parm_list


def generate(size, pmin, pmax, smin, smax):
    part = creator.Particle(parmeter_generate(pmin, pmax))
    part.speed = [random.uniform(smin, smax) for _ in range(size)]
    part.smin = smin
    part.smax = smax
    return part
Exemplo n.º 4
0
        particles_num = 22

    elif task_mode == '5_sin':
        from CPG_core.butterfly_osc.butterfly_oscillator_5_sin import oscillator_nw

        particles_num = 29

    else:
        raise print('task mode does not exist')
else:
    raise print("env :{} task does not implemented.".format(env_name))

results_dir = os.path.join(results_path, 'results')
monitor_dir = os.path.join(results_dir, 'monitor')
results = IO(os.path.join(results_path, 'results.pkl')).read_pickle()

#plot
# gen = len(results)
# fitness =[]
# for g in range (1, gen+1):
#     fitness.append(results['gen{}'.format(g)]['best_fitness'])
#
# fitness =np.array(fitness)
# gen_x = np.linspace(1,30,30)
# plt.plot(gen_x, fitness)
# plt.show()
#
# if not os.path.isdir(results_dir):
#         os.makedirs(results_dir)  # create path
# if not os.path.isdir(monitor_dir):
 def __init__(self, model_name, verbose):
     self.model_name = model_name
     self.verbose = verbose
     self.path = IO()