Skip to content

Commit

Permalink
Fix build test. (#1057)
Browse files Browse the repository at this point in the history
* 2.2.1 release

* Fix build test.

* apply yapf

* ping yapf to 0.28.0

* fix build

* use yapf 0.29

* fix yapf

* include tests in make format.

* ping autoflake and isort version.
  • Loading branch information
luomai authored Jan 14, 2020
1 parent 8e3ff1d commit c74f40c
Show file tree
Hide file tree
Showing 158 changed files with 1,043 additions and 1,067 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,17 @@ To release a new version, please update the changelog as followed:

### Fixed

- Fix README. (#PR 1044)
- Fix package info. (#PR 1046)
- Fix README. (#1044)
- Fix package info. (#1046)
- Fix build test (Using YAPF 0.29) (#1057)

### Removed

### Security

### Contributors

- @luomai (PR #1044, 1046)
- @luomai (#1044, #1046, #1057)


## [2.2.0] - 2019-09-13
Expand Down Expand Up @@ -150,7 +151,7 @@ This release is compatible with TensorFlow 2 RC1.
- Replace tf.nn.func with tf.nn.func.\_\_name\_\_ in model config. (PR #994)
- Add Reinforcement learning tutorials. (PR #995)
- Add RNN layers with simple rnn cell, GRU cell, LSTM cell. (PR #998)
- Update Seq2seq (#998)
- Update Seq2seq (#998)
- Add Seq2seqLuongAttention model (#998)

### Fixed
Expand Down
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ test:
python3 tests/files/test_utils_saveload.py

format:
autoflake -i examples/*.py
autoflake -i tensorlayer/*.py
autoflake -i tensorlayer/**/*.py
autoflake -ir examples
autoflake -ir tensorlayer
autoflake -ir tests

isort -rc examples
isort -rc tensorlayer
isort -rc tests

yapf -i examples/*.py
yapf -i tensorlayer/*.py
yapf -i tensorlayer/**/*.py
yapf -ir examples
yapf -ir tensorlayer
yapf -ir tests

install3:
pip3 install -U . --user
Expand Down
5 changes: 3 additions & 2 deletions examples/basic_tutorials/tutorial_cifar10_cnn_static.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import multiprocessing
import time

import numpy as np
import multiprocessing
import tensorflow as tf

import tensorlayer as tl
Expand Down Expand Up @@ -123,7 +124,7 @@ def _map_fn_train(img, target):

def _map_fn_test(img, target):
# 1. Crop the central [height, width] of the image.
img = tf.image.resize_with_pad(img, 24, 24)
img = tf.image.resize_with_pad(img, 24, 24)
# 2. Subtract off the mean and divide by the variance of the pixels.
img = tf.image.per_image_standardization(img)
img = tf.reshape(img, (24, 24, 3))
Expand Down
1 change: 1 addition & 0 deletions examples/basic_tutorials/tutorial_mnist_mlp_dynamic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time

import numpy as np
import tensorflow as tf

Expand Down
1 change: 1 addition & 0 deletions examples/basic_tutorials/tutorial_mnist_mlp_dynamic_2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time

import numpy as np
import tensorflow as tf

Expand Down
1 change: 1 addition & 0 deletions examples/basic_tutorials/tutorial_mnist_mlp_static.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pprint
import time

import numpy as np
import tensorflow as tf

Expand Down
1 change: 1 addition & 0 deletions examples/basic_tutorials/tutorial_mnist_mlp_static_2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time

import numpy as np
import tensorflow as tf

Expand Down
3 changes: 1 addition & 2 deletions examples/data_process/tutorial_fast_affine_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import multiprocessing
import time

import cv2
import numpy as np
import tensorflow as tf

import cv2
import tensorlayer as tl

# tl.logging.set_verbosity(tl.logging.DEBUG)
Expand Down Expand Up @@ -98,7 +98,6 @@ def _map_fn(image_path, target):
st = time.time()
for img, target in dataset:
n_step += 1
pass
assert n_step == n_epoch * n_data / batch_size
print("dataset APIs took %fs for each image" % ((time.time() - st) / batch_size / n_step)) # CPU ~ 100%

Expand Down
4 changes: 2 additions & 2 deletions examples/data_process/tutorial_tfrecord3.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ def distort_image(image, thread_id):


def prefetch_input_data(
reader, file_pattern, is_training, batch_size, values_per_shard, input_queue_capacity_factor=16,
num_reader_threads=1, shard_queue_name="filename_queue", value_queue_name="input_queue"
reader, file_pattern, is_training, batch_size, values_per_shard, input_queue_capacity_factor=16,
num_reader_threads=1, shard_queue_name="filename_queue", value_queue_name="input_queue"
):
"""Prefetches string values from disk into an input queue.
Expand Down
2 changes: 1 addition & 1 deletion examples/pretrained_cnn/tutorial_models_resnet50.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import time

import numpy as np

import tensorflow as tf

import tensorlayer as tl
from tensorlayer.models.imagenet_classes import class_names

Expand Down
21 changes: 10 additions & 11 deletions examples/reinforcement_learning/baselines/algorithms/a3c/a3c.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@
"""

import argparse
import multiprocessing
import threading
import time

import gym
import numpy as np
import tensorflow as tf
import tensorflow_probability as tfp

import gym
import tensorflow_probability as tfp
import tensorlayer as tl
from common.buffer import *
from common.networks import *
Expand All @@ -66,8 +65,8 @@
class ACNet(object):

def __init__(
self, scope, entropy_beta, action_dim, state_dim, actor_hidden_dim, actor_hidden_layer, critic_hidden_dim,
critic_hidden_layer, action_bound, globalAC=None
self, scope, entropy_beta, action_dim, state_dim, actor_hidden_dim, actor_hidden_layer, critic_hidden_dim,
critic_hidden_layer, action_bound, globalAC=None
):
self.scope = scope # the scope is for naming networks for each worker differently
self.save_path = './model'
Expand Down Expand Up @@ -107,7 +106,7 @@ def __init__(

@tf.function # convert numpy functions to tf.Operations in the TFgraph, return tensor
def update_global(
self, buffer_s, buffer_a, buffer_v_target, globalAC
self, buffer_s, buffer_a, buffer_v_target, globalAC
): # refer to the global Actor-Crtic network for updating it with samples
''' update the global critic '''
with tf.GradientTape() as tape:
Expand Down Expand Up @@ -164,8 +163,8 @@ def load_ckpt(self): # load trained weights
class Worker(object):

def __init__(
self, env_id, name, globalAC, train_episodes, gamma, update_itr, entropy_beta, action_dim, state_dim,
actor_hidden_dim, actor_hidden_layer, critic_hidden_dim, critic_hidden_layer, action_bound
self, env_id, name, globalAC, train_episodes, gamma, update_itr, entropy_beta, action_dim, state_dim,
actor_hidden_dim, actor_hidden_layer, critic_hidden_dim, critic_hidden_layer, action_bound
):
self.env = make_env(env_id)
self.name = name
Expand Down Expand Up @@ -242,9 +241,9 @@ def work(self, globalAC):


def learn(
env_id, train_episodes, test_episodes=1000, max_steps=150, number_workers=0, update_itr=10, gamma=0.99,
entropy_beta=0.005, actor_lr=5e-5, critic_lr=1e-4, actor_hidden_dim=300, actor_hidden_layer=2,
critic_hidden_dim=300, critic_hidden_layer=2, seed=2, save_interval=500, mode='train'
env_id, train_episodes, test_episodes=1000, max_steps=150, number_workers=0, update_itr=10, gamma=0.99,
entropy_beta=0.005, actor_lr=5e-5, critic_lr=1e-4, actor_hidden_dim=300, actor_hidden_layer=2,
critic_hidden_dim=300, critic_hidden_layer=2, seed=2, save_interval=500, mode='train'
):
'''
parameters
Expand Down
9 changes: 4 additions & 5 deletions examples/reinforcement_learning/baselines/algorithms/ac/ac.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@
tensorlayer >=2.0.0
"""
import argparse
import time

import gym
import numpy as np
import tensorflow as tf

import gym
import tensorlayer as tl
from common.buffer import *
from common.networks import *
Expand Down Expand Up @@ -125,9 +124,9 @@ def load_ckpt(self): # load trained weights


def learn(
env_id, train_episodes, test_episodes=1000, max_steps=1000, gamma=0.9, actor_lr=1e-3, critic_lr=1e-2,
actor_hidden_dim=30, actor_hidden_layer=1, critic_hidden_dim=30, critic_hidden_layer=1, seed=2,
save_interval=100, mode='train', render=False
env_id, train_episodes, test_episodes=1000, max_steps=1000, gamma=0.9, actor_lr=1e-3, critic_lr=1e-2,
actor_hidden_dim=30, actor_hidden_layer=1, critic_hidden_dim=30, critic_hidden_layer=1, seed=2, save_interval=100,
mode='train', render=False
):
'''
parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
"""

import os
import time

import gym
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf

import gym
import tensorlayer as tl
from common.buffer import *
from common.networks import *
Expand Down Expand Up @@ -124,8 +123,7 @@ class DDPG(object):
"""

def __init__(
self, a_dim, s_dim, hidden_dim, num_hidden_layer, a_bound, gamma, lr_a, lr_c, replay_buffer_size,
batch_size=32
self, a_dim, s_dim, hidden_dim, num_hidden_layer, a_bound, gamma, lr_a, lr_c, replay_buffer_size, batch_size=32
):
self.memory = np.zeros((replay_buffer_size, s_dim * 2 + a_dim + 1), dtype=np.float32)
self.pointer = 0
Expand Down Expand Up @@ -279,9 +277,9 @@ def load_ckpt(self):


def learn(
env_id='Pendulum-v0', train_episodes=200, test_episodes=100, max_steps=200, save_interval=10, actor_lr=1e-3,
critic_lr=2e-3, gamma=0.9, hidden_dim=30, num_hidden_layer=1, seed=1, mode='train', render=False,
replay_buffer_size=10000, batch_size=32
env_id='Pendulum-v0', train_episodes=200, test_episodes=100, max_steps=200, save_interval=10, actor_lr=1e-3,
critic_lr=2e-3, gamma=0.9, hidden_dim=30, num_hidden_layer=1, seed=1, mode='train', render=False,
replay_buffer_size=10000, batch_size=32
):
"""
learn function
Expand Down
17 changes: 7 additions & 10 deletions examples/reinforcement_learning/baselines/algorithms/dppo/dppo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@
"""

import argparse
import os
import queue
import threading
import time

import gym
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
import tensorflow_probability as tfp

import gym
import tensorflow_probability as tfp
import tensorlayer as tl
from common.buffer import *
from common.networks import *
Expand All @@ -50,8 +48,7 @@ class StochasticPolicyNetwork(Model):
''' stochastic continuous policy network for generating action according to the state '''

def __init__(
self, state_dim, action_dim, hidden_list, a_bound, log_std_min=-20, log_std_max=2, scope=None,
trainable=True
self, state_dim, action_dim, hidden_list, a_bound, log_std_min=-20, log_std_max=2, scope=None, trainable=True
):

# w_init = tf.keras.initializers.glorot_normal(
Expand Down Expand Up @@ -121,7 +118,7 @@ class PPO(object):
'''

def __init__(
self, a_dim, s_dim, hidden_list, a_max, actor_lr, critic_lr, a_update_steps, c_update_steps, save_interval
self, a_dim, s_dim, hidden_list, a_max, actor_lr, critic_lr, a_update_steps, c_update_steps, save_interval
):
self.a_dim = a_dim
self.s_dim = s_dim
Expand Down Expand Up @@ -392,9 +389,9 @@ def work(self):


def learn(
env_id='Pendulum-v0', train_episodes=1000, test_episodes=100, max_steps=200, save_interval=10, actor_lr=1e-4,
critic_lr=2e-4, gamma=0.9, hidden_dim=100, num_hidden_layer=1, seed=1, mode='train', batch_size=32,
a_update_steps=10, c_update_steps=10, n_worker=4
env_id='Pendulum-v0', train_episodes=1000, test_episodes=100, max_steps=200, save_interval=10, actor_lr=1e-4,
critic_lr=2e-4, gamma=0.9, hidden_dim=100, num_hidden_layer=1, seed=1, mode='train', batch_size=32,
a_update_steps=10, c_update_steps=10, n_worker=4
):
"""
learn function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def learn(env_id, env_type, seed, mode, **kwargs):


def core_learn(
env, mode, number_timesteps, network, optimizer, ob_scale, gamma, double_q, exploration_fraction,
exploration_final_eps, batch_size, learning_starts, target_network_update_freq, buffer_size, prioritized_replay,
prioritized_replay_alpha, prioritized_replay_beta0, save_path='dqn', save_interval=0, **kwargs
env, mode, number_timesteps, network, optimizer, ob_scale, gamma, double_q, exploration_fraction,
exploration_final_eps, batch_size, learning_starts, target_network_update_freq, buffer_size, prioritized_replay,
prioritized_replay_alpha, prioritized_replay_beta0, save_path='dqn', save_interval=0, **kwargs
):
"""
Parameters:
Expand Down
26 changes: 13 additions & 13 deletions examples/reinforcement_learning/baselines/algorithms/pg/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"""
import time

import gym
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf

import gym
import tensorlayer as tl
from common.buffer import *
from common.networks import *
Expand Down Expand Up @@ -165,18 +165,18 @@ def load(self, name='model'):


def learn(
env_id='CartPole-v0',
train_episodes=3000,
test_episodes=1000,
max_steps=1000,
lr=0.02,
gamma=0.99,
hidden_dim=30,
num_hidden_layer=1,
seed=2,
save_interval=100,
mode='train',
render=False,
env_id='CartPole-v0',
train_episodes=3000,
test_episodes=1000,
max_steps=1000,
lr=0.02,
gamma=0.99,
hidden_dim=30,
num_hidden_layer=1,
seed=2,
save_interval=100,
mode='train',
render=False,
):
"""
learn function
Expand Down
Loading

0 comments on commit c74f40c

Please sign in to comment.