Skip to content

Commit 85b5340

Browse files
committed
make format
1 parent 995a902 commit 85b5340

File tree

85 files changed

+816
-790
lines changed

Some content is hidden

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

85 files changed

+816
-790
lines changed

examples/basic_tutorials/tutorial_cifar10_cnn_static.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import tensorflow as tf
99

1010
import tensorlayer as tl
11-
from tensorlayer.layers import (BatchNorm, Conv2d, Dense, Flatten, Input,
12-
LocalResponseNorm, MaxPool2d)
11+
from tensorlayer.layers import (BatchNorm, Conv2d, Dense, Flatten, Input, LocalResponseNorm, MaxPool2d)
1312
from tensorlayer.models import Model
1413

1514
# enable debug logging

examples/data_process/tutorial_fast_affine_transform.py

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

11+
import cv2
1112
import numpy as np
1213
import tensorflow as tf
1314

14-
import cv2
1515
import tensorlayer as tl
1616

1717
# tl.logging.set_verbosity(tl.logging.DEBUG)

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/deprecated_tutorials/tutorial_imagenet_inceptionV3_distributed.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
import numpy as np
2222
import tensorflow as tf
2323
from tensorflow.contrib import slim
24-
from tensorflow.contrib.slim.python.slim.nets.inception_v3 import (inception_v3,
25-
inception_v3_arg_scope)
24+
from tensorflow.contrib.slim.python.slim.nets.inception_v3 import (inception_v3, inception_v3_arg_scope)
2625
from tensorflow.python.framework.errors_impl import OutOfRangeError
2726
from tensorflow.python.training import session_run_hook
2827
from tensorflow.python.training.basic_session_run_hooks import StopAtStepHook

examples/distributed_training/tutorial_cifar10_distributed_trainer.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
import tensorflow as tf
1919

2020
import tensorlayer as tl
21-
from tensorlayer.layers import (BatchNormLayer, Conv2d, DenseLayer,
22-
FlattenLayer, InputLayer, MaxPool2d)
21+
from tensorlayer.layers import (BatchNormLayer, Conv2d, DenseLayer, FlattenLayer, InputLayer, MaxPool2d)
2322

2423
tf.logging.set_verbosity(tf.logging.DEBUG)
2524
tl.logging.set_verbosity(tl.logging.DEBUG)

examples/reinforcement_learning/tutorial_A3C.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262

6363
tl.logging.set_verbosity(tl.logging.DEBUG)
6464

65-
6665
# add arguments in command --train/test
6766
parser = argparse.ArgumentParser(description='Train or test neural net motor controller.')
6867
parser.add_argument('--train', dest='train', action='store_true', default=False)
@@ -177,7 +176,7 @@ def save(self): # save trained weights
177176
os.makedirs(path)
178177
tl.files.save_npz(self.actor.trainable_weights, name=os.path.join(path, 'model_actor.npz'))
179178
tl.files.save_npz(self.critic.trainable_weights, name=os.path.join(path, 'model_critic.npz'))
180-
179+
181180
def load(self): # load trained weights
182181
path = os.path.join('model', '_'.join([ALG_NAME, ENV_ID]))
183182
tl.files.load_and_assign_npz(name=os.path.join(path, 'model_actor.npz'), network=self.actor)
@@ -296,7 +295,7 @@ def work(self, globalAC):
296295
COORD.join(worker_threads)
297296

298297
GLOBAL_AC.save()
299-
298+
300299
plt.plot(GLOBAL_RUNNING_R)
301300
if not os.path.exists('image'):
302301
os.makedirs('image')
@@ -319,4 +318,6 @@ def work(self, globalAC):
319318
print(
320319
'Testing | Episode: {}/{} | Episode Reward: {:.4f} | Running Time: {:.4f}'.format(
321320
episode + 1, TEST_EPISODES, episode_reward,
322-
time.time() - T0))
321+
time.time() - T0
322+
)
323+
)

examples/reinforcement_learning/tutorial_AC.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@
7878
LR_A = 0.001 # learning rate for actor
7979
LR_C = 0.01 # learning rate for critic
8080

81-
82-
8381
############################### Actor-Critic ####################################
8482

8583

@@ -205,7 +203,7 @@ def load(self): # load trained weights
205203
state_new, reward, done, info = env.step(action)
206204
state_new = state_new.astype(np.float32)
207205

208-
if done: reward = -20 # reward shaping trick
206+
if done: reward = -20 # reward shaping trick
209207
# these may helpful in some tasks
210208
# if abs(s_new[0]) >= env.observation_space.high[0]:
211209
# # cart moves more than 2.4 units from the center
@@ -240,7 +238,7 @@ def load(self): # load trained weights
240238

241239
# Early Stopping for quick check
242240
if step >= MAX_STEPS:
243-
print("Early Stopping") # Hao Dong: it is important for this task
241+
print("Early Stopping") # Hao Dong: it is important for this task
244242
break
245243
actor.save()
246244
critic.save()

examples/reinforcement_learning/tutorial_C51.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ def _train_func(self, b_o, b_index, b_m):
309309
nepisode += 1
310310
print(
311311
'Training | Episode: {} | Episode Reward: {:.4f} | Running Time: {:.4f}'.format(
312-
nepisode, episode_reward, time.time() - t0
312+
nepisode, episode_reward,
313+
time.time() - t0
313314
)
314315
) # episode num starts from 1 in print
315316

@@ -336,6 +337,7 @@ def _train_func(self, b_o, b_index, b_m):
336337
nepisode += 1
337338
print(
338339
'Testing | Episode: {} | Episode Reward: {:.4f} | Running Time: {:.4f}'.format(
339-
nepisode, episode_reward, time.time() - t0
340+
nepisode, episode_reward,
341+
time.time() - t0
340342
)
341343
)

examples/reinforcement_learning/tutorial_DDPG.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import argparse
3131
import os
32-
import threading
3332
import time
3433

3534
import gym
@@ -159,9 +158,9 @@ def get_action(self, s, greedy=False):
159158
a = self.actor(np.array([s], dtype=np.float32))[0]
160159
if greedy:
161160
return a
162-
return np.clip(np.random.normal(a, self.var),
163-
-self.action_range,
164-
self.action_range) # add randomness to action selection for exploration
161+
return np.clip(
162+
np.random.normal(a, self.var), -self.action_range, self.action_range
163+
) # add randomness to action selection for exploration
165164

166165
def learn(self):
167166
"""
@@ -276,7 +275,7 @@ def load(self):
276275
all_episode_reward.append(all_episode_reward[-1] * 0.9 + episode_reward * 0.1)
277276
print(
278277
'Training | Episode: {}/{} | Episode Reward: {:.4f} | Running Time: {:.4f}'.format(
279-
episode+1, TRAIN_EPISODES, episode_reward,
278+
episode + 1, TRAIN_EPISODES, episode_reward,
280279
time.time() - t0
281280
)
282281
)
@@ -301,4 +300,6 @@ def load(self):
301300
print(
302301
'Testing | Episode: {}/{} | Episode Reward: {:.4f} | Running Time: {:.4f}'.format(
303302
episode + 1, TEST_EPISODES, episode_reward,
304-
time.time() - t0))
303+
time.time() - t0
304+
)
305+
)

examples/reinforcement_learning/tutorial_DPPO.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
# ppo-clip parameters
7474
EPSILON = 0.2
7575

76-
7776
############################### DPPO ####################################
7877

7978

@@ -305,7 +304,8 @@ def work(self):
305304

306305
print(
307306
'Training | Episode: {}/{} | Worker: {} | Episode Reward: {:.4f} | Running Time: {:.4f}'.format(
308-
GLOBAL_EP + 1, TRAIN_EPISODES, self.wid, ep_r, time.time() - T0
307+
GLOBAL_EP + 1, TRAIN_EPISODES, self.wid, ep_r,
308+
time.time() - T0
309309
)
310310
)
311311
# record reward changes, plot later
@@ -372,4 +372,6 @@ def work(self):
372372
print(
373373
'Testing | Episode: {}/{} | Episode Reward: {:.4f} | Running Time: {:.4f}'.format(
374374
episode + 1, TEST_EPISODES, episode_reward,
375-
time.time() - T0))
375+
time.time() - T0
376+
)
377+
)

examples/reinforcement_learning/tutorial_DQN.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
num_episodes = 10000
6262
render = False # display the game environment
6363

64-
6564
##################### DQN ##########################
6665

6766

@@ -140,7 +139,7 @@ def load_ckpt(model): # load trained weights
140139
rAll += r
141140
s = s1
142141
## Reduce chance of random action if an episode is done.
143-
if d == True:
142+
if d ==True:
144143
e = 1. / ((i / 50) + 10) # reduce e, GLIE: Greey in the limit with infinite Exploration
145144
break
146145

examples/reinforcement_learning/tutorial_DQN_variants.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,8 @@ def load(self, path):
399399
nepisode += 1
400400
print(
401401
'Training | Episode: {} | Episode Reward: {:.4f} | Running Time: {:.4f}'.format(
402-
nepisode, episode_reward, time.time() - t0
402+
nepisode, episode_reward,
403+
time.time() - t0
403404
)
404405
) # episode num starts from 1 in print
405406

@@ -426,6 +427,7 @@ def load(self, path):
426427
nepisode += 1
427428
print(
428429
'Testing | Episode: {} | Episode Reward: {:.4f} | Running Time: {:.4f}'.format(
429-
nepisode, episode_reward, time.time() - t0
430+
nepisode, episode_reward,
431+
time.time() - t0
430432
)
431433
)

examples/reinforcement_learning/tutorial_PG.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class PolicyGradient:
6060
"""
6161
PG class
6262
"""
63+
6364
def __init__(self, state_dim, action_num, learning_rate=0.02, gamma=0.99):
6465
self.gamma = gamma
6566

@@ -113,7 +114,9 @@ def learn(self):
113114

114115
with tf.GradientTape() as tape:
115116
_logits = self.model(np.vstack(self.state_buffer))
116-
neg_log_prob = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=_logits, labels=np.array(self.action_buffer))
117+
neg_log_prob = tf.nn.sparse_softmax_cross_entropy_with_logits(
118+
logits=_logits, labels=np.array(self.action_buffer)
119+
)
117120
loss = tf.reduce_mean(neg_log_prob * discounted_reward_buffer_norm)
118121

119122
grad = tape.gradient(loss, self.model.trainable_weights)
@@ -195,7 +198,9 @@ def load(self):
195198
print(
196199
'Training | Episode: {}/{} | Episode Reward: {:.0f} | Running Time: {:.4f}'.format(
197200
episode + 1, TRAIN_EPISODES, episode_reward,
198-
time.time() - t0))
201+
time.time() - t0
202+
)
203+
)
199204

200205
if episode == 0:
201206
all_episode_reward.append(episode_reward)
@@ -223,4 +228,6 @@ def load(self):
223228
print(
224229
'Testing | Episode: {}/{} | Episode Reward: {:.0f} | Running Time: {:.4f}'.format(
225230
episode + 1, TEST_EPISODES, episode_reward,
226-
time.time() - t0))
231+
time.time() - t0
232+
)
233+
)

examples/reinforcement_learning/tutorial_PPO.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@
6363
# ppo-clip parameters
6464
EPSILON = 0.2
6565

66-
6766
############################### PPO ####################################
6867

6968

7069
class PPO(object):
7170
"""
7271
PPO class
7372
"""
73+
7474
def __init__(self, state_dim, action_dim, action_bound, method='clip'):
7575
# critic
7676
with tf.name_scope('critic'):
@@ -288,7 +288,9 @@ def finish_path(self, next_state):
288288
agent.finish_path(state_)
289289
print(
290290
'Training | Episode: {}/{} | Episode Reward: {:.4f} | Running Time: {:.4f}'.format(
291-
episode + 1, TRAIN_EPISODES, episode_reward, time.time() - t0)
291+
episode + 1, TRAIN_EPISODES, episode_reward,
292+
time.time() - t0
293+
)
292294
)
293295
if episode == 0:
294296
all_episode_reward.append(episode_reward)
@@ -316,4 +318,6 @@ def finish_path(self, next_state):
316318
print(
317319
'Testing | Episode: {}/{} | Episode Reward: {:.4f} | Running Time: {:.4f}'.format(
318320
episode + 1, TEST_EPISODES, episode_reward,
319-
time.time() - t0))
321+
time.time() - t0
322+
)
323+
)

examples/reinforcement_learning/tutorial_Qlearning.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
parser.add_argument(
2525
'--save_path', default=None, help='folder to save if mode == train else model path,'
26-
'qnet will be saved once target net update'
26+
'qnet will be saved once target net update'
2727
)
2828
parser.add_argument('--seed', help='random seed', type=int, default=0)
2929
parser.add_argument('--env_id', default='FrozenLake-v0')
@@ -65,7 +65,8 @@
6565
break
6666
print(
6767
'Training | Episode: {}/{} | Episode Reward: {:.4f} | Running Time: {:.4f}'.format(
68-
i + 1, num_episodes, rAll, time.time() - t0
68+
i + 1, num_episodes, rAll,
69+
time.time() - t0
6970
)
7071
)
7172
if i == 0:
@@ -106,6 +107,7 @@
106107
break
107108
print(
108109
'Testing | Episode: {}/{} | Episode Reward: {:.4f} | Running Time: {:.4f}'.format(
109-
i + 1, num_episodes, rAll, time.time() - t0
110+
i + 1, num_episodes, rAll,
111+
time.time() - t0
110112
)
111113
)

0 commit comments

Comments
 (0)