Skip to content

Commit c74f40c

Browse files
authored
Fix build test. (#1057)
* 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.
1 parent 8e3ff1d commit c74f40c

File tree

158 files changed

+1043
-1067
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+1043
-1067
lines changed

CHANGELOG.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,17 @@ To release a new version, please update the changelog as followed:
8080

8181
### Fixed
8282

83-
- Fix README. (#PR 1044)
84-
- Fix package info. (#PR 1046)
83+
- Fix README. (#1044)
84+
- Fix package info. (#1046)
85+
- Fix build test (Using YAPF 0.29) (#1057)
8586

8687
### Removed
8788

8889
### Security
8990

9091
### Contributors
9192

92-
- @luomai (PR #1044, 1046)
93+
- @luomai (#1044, #1046, #1057)
9394

9495

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

156157
### Fixed

Makefile

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ test:
1414
python3 tests/files/test_utils_saveload.py
1515

1616
format:
17-
autoflake -i examples/*.py
18-
autoflake -i tensorlayer/*.py
19-
autoflake -i tensorlayer/**/*.py
17+
autoflake -ir examples
18+
autoflake -ir tensorlayer
19+
autoflake -ir tests
2020

2121
isort -rc examples
2222
isort -rc tensorlayer
23+
isort -rc tests
2324

24-
yapf -i examples/*.py
25-
yapf -i tensorlayer/*.py
26-
yapf -i tensorlayer/**/*.py
25+
yapf -ir examples
26+
yapf -ir tensorlayer
27+
yapf -ir tests
2728

2829
install3:
2930
pip3 install -U . --user

examples/basic_tutorials/tutorial_cifar10_cnn_static.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4+
import multiprocessing
45
import time
6+
57
import numpy as np
6-
import multiprocessing
78
import tensorflow as tf
89

910
import tensorlayer as tl
@@ -123,7 +124,7 @@ def _map_fn_train(img, target):
123124

124125
def _map_fn_test(img, target):
125126
# 1. Crop the central [height, width] of the image.
126-
img = tf.image.resize_with_pad(img, 24, 24)
127+
img = tf.image.resize_with_pad(img, 24, 24)
127128
# 2. Subtract off the mean and divide by the variance of the pixels.
128129
img = tf.image.per_image_standardization(img)
129130
img = tf.reshape(img, (24, 24, 3))

examples/basic_tutorials/tutorial_mnist_mlp_dynamic.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import time
2+
23
import numpy as np
34
import tensorflow as tf
45

examples/basic_tutorials/tutorial_mnist_mlp_dynamic_2.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import time
2+
23
import numpy as np
34
import tensorflow as tf
45

examples/basic_tutorials/tutorial_mnist_mlp_static.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pprint
22
import time
3+
34
import numpy as np
45
import tensorflow as tf
56

examples/basic_tutorials/tutorial_mnist_mlp_static_2.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import time
2+
23
import numpy as np
34
import tensorflow as tf
45

examples/data_process/tutorial_fast_affine_transform.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import multiprocessing
99
import time
1010

11-
import cv2
1211
import numpy as np
1312
import tensorflow as tf
1413

14+
import cv2
1515
import tensorlayer as tl
1616

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

examples/data_process/tutorial_tfrecord3.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ def distort_image(image, thread_id):
231231

232232

233233
def prefetch_input_data(
234-
reader, file_pattern, is_training, batch_size, values_per_shard, input_queue_capacity_factor=16,
235-
num_reader_threads=1, shard_queue_name="filename_queue", value_queue_name="input_queue"
234+
reader, file_pattern, is_training, batch_size, values_per_shard, input_queue_capacity_factor=16,
235+
num_reader_threads=1, shard_queue_name="filename_queue", value_queue_name="input_queue"
236236
):
237237
"""Prefetches string values from disk into an input queue.
238238

examples/pretrained_cnn/tutorial_models_resnet50.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import time
99

1010
import numpy as np
11-
1211
import tensorflow as tf
12+
1313
import tensorlayer as tl
1414
from tensorlayer.models.imagenet_classes import class_names
1515

examples/reinforcement_learning/baselines/algorithms/a3c/a3c.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,15 @@
4040
4141
"""
4242

43-
import argparse
4443
import multiprocessing
4544
import threading
4645
import time
4746

48-
import gym
4947
import numpy as np
5048
import tensorflow as tf
51-
import tensorflow_probability as tfp
5249

50+
import gym
51+
import tensorflow_probability as tfp
5352
import tensorlayer as tl
5453
from common.buffer import *
5554
from common.networks import *
@@ -66,8 +65,8 @@
6665
class ACNet(object):
6766

6867
def __init__(
69-
self, scope, entropy_beta, action_dim, state_dim, actor_hidden_dim, actor_hidden_layer, critic_hidden_dim,
70-
critic_hidden_layer, action_bound, globalAC=None
68+
self, scope, entropy_beta, action_dim, state_dim, actor_hidden_dim, actor_hidden_layer, critic_hidden_dim,
69+
critic_hidden_layer, action_bound, globalAC=None
7170
):
7271
self.scope = scope # the scope is for naming networks for each worker differently
7372
self.save_path = './model'
@@ -107,7 +106,7 @@ def __init__(
107106

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

166165
def __init__(
167-
self, env_id, name, globalAC, train_episodes, gamma, update_itr, entropy_beta, action_dim, state_dim,
168-
actor_hidden_dim, actor_hidden_layer, critic_hidden_dim, critic_hidden_layer, action_bound
166+
self, env_id, name, globalAC, train_episodes, gamma, update_itr, entropy_beta, action_dim, state_dim,
167+
actor_hidden_dim, actor_hidden_layer, critic_hidden_dim, critic_hidden_layer, action_bound
169168
):
170169
self.env = make_env(env_id)
171170
self.name = name
@@ -242,9 +241,9 @@ def work(self, globalAC):
242241

243242

244243
def learn(
245-
env_id, train_episodes, test_episodes=1000, max_steps=150, number_workers=0, update_itr=10, gamma=0.99,
246-
entropy_beta=0.005, actor_lr=5e-5, critic_lr=1e-4, actor_hidden_dim=300, actor_hidden_layer=2,
247-
critic_hidden_dim=300, critic_hidden_layer=2, seed=2, save_interval=500, mode='train'
244+
env_id, train_episodes, test_episodes=1000, max_steps=150, number_workers=0, update_itr=10, gamma=0.99,
245+
entropy_beta=0.005, actor_lr=5e-5, critic_lr=1e-4, actor_hidden_dim=300, actor_hidden_layer=2,
246+
critic_hidden_dim=300, critic_hidden_layer=2, seed=2, save_interval=500, mode='train'
248247
):
249248
'''
250249
parameters

examples/reinforcement_learning/baselines/algorithms/ac/ac.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@
4141
tensorlayer >=2.0.0
4242
4343
"""
44-
import argparse
4544
import time
4645

47-
import gym
4846
import numpy as np
4947
import tensorflow as tf
5048

49+
import gym
5150
import tensorlayer as tl
5251
from common.buffer import *
5352
from common.networks import *
@@ -125,9 +124,9 @@ def load_ckpt(self): # load trained weights
125124

126125

127126
def learn(
128-
env_id, train_episodes, test_episodes=1000, max_steps=1000, gamma=0.9, actor_lr=1e-3, critic_lr=1e-2,
129-
actor_hidden_dim=30, actor_hidden_layer=1, critic_hidden_dim=30, critic_hidden_layer=1, seed=2,
130-
save_interval=100, mode='train', render=False
127+
env_id, train_episodes, test_episodes=1000, max_steps=1000, gamma=0.9, actor_lr=1e-3, critic_lr=1e-2,
128+
actor_hidden_dim=30, actor_hidden_layer=1, critic_hidden_dim=30, critic_hidden_layer=1, seed=2, save_interval=100,
129+
mode='train', render=False
131130
):
132131
'''
133132
parameters

examples/reinforcement_learning/baselines/algorithms/ddpg/ddpg.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
2020
"""
2121

22-
import os
2322
import time
2423

25-
import gym
2624
import matplotlib.pyplot as plt
2725
import numpy as np
2826
import tensorflow as tf
2927

28+
import gym
3029
import tensorlayer as tl
3130
from common.buffer import *
3231
from common.networks import *
@@ -124,8 +123,7 @@ class DDPG(object):
124123
"""
125124

126125
def __init__(
127-
self, a_dim, s_dim, hidden_dim, num_hidden_layer, a_bound, gamma, lr_a, lr_c, replay_buffer_size,
128-
batch_size=32
126+
self, a_dim, s_dim, hidden_dim, num_hidden_layer, a_bound, gamma, lr_a, lr_c, replay_buffer_size, batch_size=32
129127
):
130128
self.memory = np.zeros((replay_buffer_size, s_dim * 2 + a_dim + 1), dtype=np.float32)
131129
self.pointer = 0
@@ -279,9 +277,9 @@ def load_ckpt(self):
279277

280278

281279
def learn(
282-
env_id='Pendulum-v0', train_episodes=200, test_episodes=100, max_steps=200, save_interval=10, actor_lr=1e-3,
283-
critic_lr=2e-3, gamma=0.9, hidden_dim=30, num_hidden_layer=1, seed=1, mode='train', render=False,
284-
replay_buffer_size=10000, batch_size=32
280+
env_id='Pendulum-v0', train_episodes=200, test_episodes=100, max_steps=200, save_interval=10, actor_lr=1e-3,
281+
critic_lr=2e-3, gamma=0.9, hidden_dim=30, num_hidden_layer=1, seed=1, mode='train', render=False,
282+
replay_buffer_size=10000, batch_size=32
285283
):
286284
"""
287285
learn function

examples/reinforcement_learning/baselines/algorithms/dppo/dppo.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@
2020
2121
"""
2222

23-
import argparse
24-
import os
2523
import queue
2624
import threading
2725
import time
2826

29-
import gym
3027
import matplotlib.pyplot as plt
3128
import numpy as np
3229
import tensorflow as tf
33-
import tensorflow_probability as tfp
3430

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

5250
def __init__(
53-
self, state_dim, action_dim, hidden_list, a_bound, log_std_min=-20, log_std_max=2, scope=None,
54-
trainable=True
51+
self, state_dim, action_dim, hidden_list, a_bound, log_std_min=-20, log_std_max=2, scope=None, trainable=True
5552
):
5653

5754
# w_init = tf.keras.initializers.glorot_normal(
@@ -121,7 +118,7 @@ class PPO(object):
121118
'''
122119

123120
def __init__(
124-
self, a_dim, s_dim, hidden_list, a_max, actor_lr, critic_lr, a_update_steps, c_update_steps, save_interval
121+
self, a_dim, s_dim, hidden_list, a_max, actor_lr, critic_lr, a_update_steps, c_update_steps, save_interval
125122
):
126123
self.a_dim = a_dim
127124
self.s_dim = s_dim
@@ -392,9 +389,9 @@ def work(self):
392389

393390

394391
def learn(
395-
env_id='Pendulum-v0', train_episodes=1000, test_episodes=100, max_steps=200, save_interval=10, actor_lr=1e-4,
396-
critic_lr=2e-4, gamma=0.9, hidden_dim=100, num_hidden_layer=1, seed=1, mode='train', batch_size=32,
397-
a_update_steps=10, c_update_steps=10, n_worker=4
392+
env_id='Pendulum-v0', train_episodes=1000, test_episodes=100, max_steps=200, save_interval=10, actor_lr=1e-4,
393+
critic_lr=2e-4, gamma=0.9, hidden_dim=100, num_hidden_layer=1, seed=1, mode='train', batch_size=32,
394+
a_update_steps=10, c_update_steps=10, n_worker=4
398395
):
399396
"""
400397
learn function

examples/reinforcement_learning/baselines/algorithms/dqn/dqn.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def learn(env_id, env_type, seed, mode, **kwargs):
3838

3939

4040
def core_learn(
41-
env, mode, number_timesteps, network, optimizer, ob_scale, gamma, double_q, exploration_fraction,
42-
exploration_final_eps, batch_size, learning_starts, target_network_update_freq, buffer_size, prioritized_replay,
43-
prioritized_replay_alpha, prioritized_replay_beta0, save_path='dqn', save_interval=0, **kwargs
41+
env, mode, number_timesteps, network, optimizer, ob_scale, gamma, double_q, exploration_fraction,
42+
exploration_final_eps, batch_size, learning_starts, target_network_update_freq, buffer_size, prioritized_replay,
43+
prioritized_replay_alpha, prioritized_replay_beta0, save_path='dqn', save_interval=0, **kwargs
4444
):
4545
"""
4646
Parameters:

examples/reinforcement_learning/baselines/algorithms/pg/pg.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
"""
2121
import time
2222

23-
import gym
2423
import matplotlib.pyplot as plt
2524
import numpy as np
2625
import tensorflow as tf
2726

27+
import gym
2828
import tensorlayer as tl
2929
from common.buffer import *
3030
from common.networks import *
@@ -165,18 +165,18 @@ def load(self, name='model'):
165165

166166

167167
def learn(
168-
env_id='CartPole-v0',
169-
train_episodes=3000,
170-
test_episodes=1000,
171-
max_steps=1000,
172-
lr=0.02,
173-
gamma=0.99,
174-
hidden_dim=30,
175-
num_hidden_layer=1,
176-
seed=2,
177-
save_interval=100,
178-
mode='train',
179-
render=False,
168+
env_id='CartPole-v0',
169+
train_episodes=3000,
170+
test_episodes=1000,
171+
max_steps=1000,
172+
lr=0.02,
173+
gamma=0.99,
174+
hidden_dim=30,
175+
num_hidden_layer=1,
176+
seed=2,
177+
save_interval=100,
178+
mode='train',
179+
render=False,
180180
):
181181
"""
182182
learn function

0 commit comments

Comments
 (0)