diff --git a/CHANGELOG.md b/CHANGELOG.md index a19b722b4..83bcab0f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,8 +80,9 @@ 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 @@ -89,7 +90,7 @@ To release a new version, please update the changelog as followed: ### Contributors -- @luomai (PR #1044, 1046) +- @luomai (#1044, #1046, #1057) ## [2.2.0] - 2019-09-13 @@ -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 diff --git a/Makefile b/Makefile index 4fbfd85c5..9ce4e51f6 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/examples/basic_tutorials/tutorial_cifar10_cnn_static.py b/examples/basic_tutorials/tutorial_cifar10_cnn_static.py index 57c22bdac..53720511d 100644 --- a/examples/basic_tutorials/tutorial_cifar10_cnn_static.py +++ b/examples/basic_tutorials/tutorial_cifar10_cnn_static.py @@ -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 @@ -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)) diff --git a/examples/basic_tutorials/tutorial_mnist_mlp_dynamic.py b/examples/basic_tutorials/tutorial_mnist_mlp_dynamic.py index e255c7a47..d986b01a3 100644 --- a/examples/basic_tutorials/tutorial_mnist_mlp_dynamic.py +++ b/examples/basic_tutorials/tutorial_mnist_mlp_dynamic.py @@ -1,4 +1,5 @@ import time + import numpy as np import tensorflow as tf diff --git a/examples/basic_tutorials/tutorial_mnist_mlp_dynamic_2.py b/examples/basic_tutorials/tutorial_mnist_mlp_dynamic_2.py index aa301fe70..58695c8ac 100644 --- a/examples/basic_tutorials/tutorial_mnist_mlp_dynamic_2.py +++ b/examples/basic_tutorials/tutorial_mnist_mlp_dynamic_2.py @@ -1,4 +1,5 @@ import time + import numpy as np import tensorflow as tf diff --git a/examples/basic_tutorials/tutorial_mnist_mlp_static.py b/examples/basic_tutorials/tutorial_mnist_mlp_static.py index 3929813d7..358a0e561 100644 --- a/examples/basic_tutorials/tutorial_mnist_mlp_static.py +++ b/examples/basic_tutorials/tutorial_mnist_mlp_static.py @@ -1,5 +1,6 @@ import pprint import time + import numpy as np import tensorflow as tf diff --git a/examples/basic_tutorials/tutorial_mnist_mlp_static_2.py b/examples/basic_tutorials/tutorial_mnist_mlp_static_2.py index 338838366..a4110eafb 100644 --- a/examples/basic_tutorials/tutorial_mnist_mlp_static_2.py +++ b/examples/basic_tutorials/tutorial_mnist_mlp_static_2.py @@ -1,4 +1,5 @@ import time + import numpy as np import tensorflow as tf diff --git a/examples/data_process/tutorial_fast_affine_transform.py b/examples/data_process/tutorial_fast_affine_transform.py index 52452ffd5..9f817e90f 100644 --- a/examples/data_process/tutorial_fast_affine_transform.py +++ b/examples/data_process/tutorial_fast_affine_transform.py @@ -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) @@ -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% diff --git a/examples/data_process/tutorial_tfrecord3.py b/examples/data_process/tutorial_tfrecord3.py index 9e5751a25..96ff714e7 100644 --- a/examples/data_process/tutorial_tfrecord3.py +++ b/examples/data_process/tutorial_tfrecord3.py @@ -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. diff --git a/examples/pretrained_cnn/tutorial_models_resnet50.py b/examples/pretrained_cnn/tutorial_models_resnet50.py index b5055cee3..b8f8b1c28 100644 --- a/examples/pretrained_cnn/tutorial_models_resnet50.py +++ b/examples/pretrained_cnn/tutorial_models_resnet50.py @@ -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 diff --git a/examples/reinforcement_learning/baselines/algorithms/a3c/a3c.py b/examples/reinforcement_learning/baselines/algorithms/a3c/a3c.py index 610dfec32..f4a6ad808 100644 --- a/examples/reinforcement_learning/baselines/algorithms/a3c/a3c.py +++ b/examples/reinforcement_learning/baselines/algorithms/a3c/a3c.py @@ -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 * @@ -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' @@ -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: @@ -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 @@ -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 diff --git a/examples/reinforcement_learning/baselines/algorithms/ac/ac.py b/examples/reinforcement_learning/baselines/algorithms/ac/ac.py index 3f418c9ad..dd3f505b6 100644 --- a/examples/reinforcement_learning/baselines/algorithms/ac/ac.py +++ b/examples/reinforcement_learning/baselines/algorithms/ac/ac.py @@ -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 * @@ -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 diff --git a/examples/reinforcement_learning/baselines/algorithms/ddpg/ddpg.py b/examples/reinforcement_learning/baselines/algorithms/ddpg/ddpg.py index 532b11c7d..9a23389d5 100644 --- a/examples/reinforcement_learning/baselines/algorithms/ddpg/ddpg.py +++ b/examples/reinforcement_learning/baselines/algorithms/ddpg/ddpg.py @@ -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 * @@ -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 @@ -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 diff --git a/examples/reinforcement_learning/baselines/algorithms/dppo/dppo.py b/examples/reinforcement_learning/baselines/algorithms/dppo/dppo.py index 9049bd8a9..4b2270508 100644 --- a/examples/reinforcement_learning/baselines/algorithms/dppo/dppo.py +++ b/examples/reinforcement_learning/baselines/algorithms/dppo/dppo.py @@ -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 * @@ -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( @@ -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 @@ -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 diff --git a/examples/reinforcement_learning/baselines/algorithms/dqn/dqn.py b/examples/reinforcement_learning/baselines/algorithms/dqn/dqn.py index f83540951..54fb15dad 100644 --- a/examples/reinforcement_learning/baselines/algorithms/dqn/dqn.py +++ b/examples/reinforcement_learning/baselines/algorithms/dqn/dqn.py @@ -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: diff --git a/examples/reinforcement_learning/baselines/algorithms/pg/pg.py b/examples/reinforcement_learning/baselines/algorithms/pg/pg.py index 916836e70..613a11de4 100644 --- a/examples/reinforcement_learning/baselines/algorithms/pg/pg.py +++ b/examples/reinforcement_learning/baselines/algorithms/pg/pg.py @@ -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 * @@ -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 diff --git a/examples/reinforcement_learning/baselines/algorithms/ppo/ppo.py b/examples/reinforcement_learning/baselines/algorithms/ppo/ppo.py index ae6d5c8d8..ddce3c071 100644 --- a/examples/reinforcement_learning/baselines/algorithms/ppo/ppo.py +++ b/examples/reinforcement_learning/baselines/algorithms/ppo/ppo.py @@ -19,16 +19,14 @@ tensorlayer >=2.0.0 """ -import argparse -import os 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 * @@ -41,8 +39,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( @@ -303,9 +300,9 @@ def load_ckpt(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', render=False, - batch_size=32, a_update_steps=10, c_update_steps=10 + 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', render=False, batch_size=32, + a_update_steps=10, c_update_steps=10 ): """ learn function diff --git a/examples/reinforcement_learning/baselines/algorithms/sac/sac.py b/examples/reinforcement_learning/baselines/algorithms/sac/sac.py index aebb48ba7..3ecf67cde 100644 --- a/examples/reinforcement_learning/baselines/algorithms/sac/sac.py +++ b/examples/reinforcement_learning/baselines/algorithms/sac/sac.py @@ -16,22 +16,19 @@ pip install box2d box2d-kengz --user ''' -import argparse -import math -import random import time -import gym import matplotlib.pyplot as plt import numpy as np import tensorflow as tf -import tensorflow_probability as tfp -from IPython.display import clear_output +import gym +import tensorflow_probability as tfp import tensorlayer as tl from common.buffer import * from common.networks import * from common.utils import * +from IPython.display import clear_output from tensorlayer.layers import Dense from tensorlayer.models import Model @@ -44,7 +41,7 @@ class PolicyNetwork(Model): def __init__( - self, num_inputs, num_actions, hidden_dim, action_range=1., init_w=3e-3, log_std_min=-20, log_std_max=2 + self, num_inputs, num_actions, hidden_dim, action_range=1., init_w=3e-3, log_std_min=-20, log_std_max=2 ): super(PolicyNetwork, self).__init__() @@ -121,8 +118,8 @@ def sample_action(self, ): class SAC_Trainer(): def __init__( - self, replay_buffer, hidden_dim, state_dim, action_dim, action_range, soft_q_lr=3e-4, policy_lr=3e-4, - alpha_lr=3e-4 + self, replay_buffer, hidden_dim, state_dim, action_dim, action_range, soft_q_lr=3e-4, policy_lr=3e-4, + alpha_lr=3e-4 ): self.replay_buffer = replay_buffer diff --git a/examples/reinforcement_learning/baselines/algorithms/td3/td3.py b/examples/reinforcement_learning/baselines/algorithms/td3/td3.py index 46f27ad09..ff056d1b2 100644 --- a/examples/reinforcement_learning/baselines/algorithms/td3/td3.py +++ b/examples/reinforcement_learning/baselines/algorithms/td3/td3.py @@ -37,22 +37,20 @@ ''' -import argparse -import math import random import time -import gym import matplotlib.pyplot as plt import numpy as np import tensorflow as tf -import tensorflow_probability as tfp -from IPython.display import clear_output +import gym +import tensorflow_probability as tfp import tensorlayer as tl from common.buffer import * from common.networks import * from common.utils import * +from IPython.display import clear_output from tensorlayer.layers import Dense from tensorlayer.models import Model @@ -133,8 +131,8 @@ def sample_action(self, ): class TD3_Trainer(): def __init__( - self, replay_buffer, hidden_dim, state_dim, action_dim, action_range, policy_target_update_interval=1, - q_lr=3e-4, policy_lr=3e-4 + self, replay_buffer, hidden_dim, state_dim, action_dim, action_range, policy_target_update_interval=1, + q_lr=3e-4, policy_lr=3e-4 ): self.replay_buffer = replay_buffer diff --git a/examples/reinforcement_learning/baselines/algorithms/trpo/trpo.py b/examples/reinforcement_learning/baselines/algorithms/trpo/trpo.py index 9cef6da28..5feded041 100644 --- a/examples/reinforcement_learning/baselines/algorithms/trpo/trpo.py +++ b/examples/reinforcement_learning/baselines/algorithms/trpo/trpo.py @@ -24,18 +24,18 @@ import os import time -import gym import matplotlib.pyplot as plt import numpy as np import scipy.signal import tensorflow as tf -import tensorflow_probability as tfp -from gym.spaces import Box, Discrete +import gym +import tensorflow_probability as tfp import tensorlayer as tl from common.buffer import * from common.networks import * from common.utils import * +from gym.spaces import Box, Discrete EPS = 1e-8 # epsilon @@ -297,8 +297,7 @@ def cal_outputs_1(self, states, actions, old_log_std_ph, old_mu_ph): def mlp_actor_critic( - x: 'env.observation_space', a: 'env.action_space', hidden_sizes=(64, 64), activation=tf.tanh, - output_activation=None + x: 'env.observation_space', a: 'env.action_space', hidden_sizes=(64, 64), activation=tf.tanh, output_activation=None ): """ create actor and critic @@ -428,8 +427,8 @@ class TRPO: """ def __init__( - self, obs_space, act_space, hidden_list, max_steps, gamma, lam, critic_lr, damping_coeff, cg_iters, delta, - backtrack_iters, backtrack_coeff, train_critic_iters + self, obs_space, act_space, hidden_list, max_steps, gamma, lam, critic_lr, damping_coeff, cg_iters, delta, + backtrack_iters, backtrack_coeff, train_critic_iters ): obs_dim = obs_space.shape act_dim = act_space.shape @@ -636,9 +635,9 @@ def set_and_eval(step): def learn( - env_id='Pendulum-v0', train_episodes=500, test_episodes=100, max_steps=4000, save_interval=10, critic_lr=1e-3, - gamma=0.99, hidden_dim=64, num_hidden_layer=2, seed=1, mode='train', render=False, c_update_steps=80, lam=0.97, - damping_coeff=0.1, cg_iters=10, delta=0.01, backtrack_iters=10, backtrack_coeff=0.8, max_ep_len=1000 + env_id='Pendulum-v0', train_episodes=500, test_episodes=100, max_steps=4000, save_interval=10, critic_lr=1e-3, + gamma=0.99, hidden_dim=64, num_hidden_layer=2, seed=1, mode='train', render=False, c_update_steps=80, lam=0.97, + damping_coeff=0.1, cg_iters=10, delta=0.01, backtrack_iters=10, backtrack_coeff=0.8, max_ep_len=1000 ): """ learn function diff --git a/examples/reinforcement_learning/baselines/common/dm2gym.py b/examples/reinforcement_learning/baselines/common/dm2gym.py index 60dfde4d3..8b0825979 100644 --- a/examples/reinforcement_learning/baselines/common/dm2gym.py +++ b/examples/reinforcement_learning/baselines/common/dm2gym.py @@ -26,8 +26,9 @@ import os import sys -import gym import numpy as np + +import gym from dm_control import suite from dm_control.rl import specs from gym import core, spaces diff --git a/examples/reinforcement_learning/baselines/common/networks.py b/examples/reinforcement_learning/baselines/common/networks.py index 99160d854..7536582c2 100644 --- a/examples/reinforcement_learning/baselines/common/networks.py +++ b/examples/reinforcement_learning/baselines/common/networks.py @@ -6,14 +6,11 @@ tensorlayer==2.0.1 """ -import operator -import os -import random import numpy as np import tensorflow as tf -import tensorflow_probability as tfp +import tensorflow_probability as tfp import tensorlayer as tl from tensorlayer.layers import Dense, Input from tensorlayer.models import Model diff --git a/examples/reinforcement_learning/baselines/common/utils.py b/examples/reinforcement_learning/baselines/common/utils.py index 54819911f..f43941cb9 100644 --- a/examples/reinforcement_learning/baselines/common/utils.py +++ b/examples/reinforcement_learning/baselines/common/utils.py @@ -6,16 +6,14 @@ tensorlayer==2.0.1 """ -import operator import os -import random import re from importlib import import_module -import gym import matplotlib.pyplot as plt import numpy as np +import gym import tensorlayer as tl diff --git a/examples/reinforcement_learning/baselines/common/wrappers.py b/examples/reinforcement_learning/baselines/common/wrappers.py index b62fa409a..4ae724d3a 100644 --- a/examples/reinforcement_learning/baselines/common/wrappers.py +++ b/examples/reinforcement_learning/baselines/common/wrappers.py @@ -7,9 +7,10 @@ from multiprocessing import Pipe, Process, cpu_count from sys import platform +import numpy as np + import cv2 import gym -import numpy as np from gym import spaces __all__ = ( diff --git a/examples/reinforcement_learning/baselines/main.py b/examples/reinforcement_learning/baselines/main.py index ca378aa7b..ff8e924be 100644 --- a/examples/reinforcement_learning/baselines/main.py +++ b/examples/reinforcement_learning/baselines/main.py @@ -4,7 +4,6 @@ ''' import argparse -import os from common.utils import learn, parse_all_args diff --git a/examples/reinforcement_learning/tutorial_A3C.py b/examples/reinforcement_learning/tutorial_A3C.py index 36e74e9d1..f71ca2e46 100644 --- a/examples/reinforcement_learning/tutorial_A3C.py +++ b/examples/reinforcement_learning/tutorial_A3C.py @@ -49,11 +49,11 @@ 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 tensorlayer.layers import DenseLayer, InputLayer @@ -122,7 +122,7 @@ def get_critic(input_shape): # we use Value-function here, but not Q-function. @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: diff --git a/examples/reinforcement_learning/tutorial_AC.py b/examples/reinforcement_learning/tutorial_AC.py index d2f4ff1ac..f433541af 100644 --- a/examples/reinforcement_learning/tutorial_AC.py +++ b/examples/reinforcement_learning/tutorial_AC.py @@ -48,10 +48,10 @@ import argparse import time -import gym import numpy as np import tensorflow as tf +import gym import tensorlayer as tl tl.logging.set_verbosity(tl.logging.DEBUG) diff --git a/examples/reinforcement_learning/tutorial_DDPG.py b/examples/reinforcement_learning/tutorial_DDPG.py index 50c767b00..a62b43d58 100644 --- a/examples/reinforcement_learning/tutorial_DDPG.py +++ b/examples/reinforcement_learning/tutorial_DDPG.py @@ -31,11 +31,11 @@ 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 parser = argparse.ArgumentParser(description='Train or test neural net motor controller.') diff --git a/examples/reinforcement_learning/tutorial_DPPO.py b/examples/reinforcement_learning/tutorial_DPPO.py index f03c241b0..b9f6cc6bf 100644 --- a/examples/reinforcement_learning/tutorial_DPPO.py +++ b/examples/reinforcement_learning/tutorial_DPPO.py @@ -35,12 +35,12 @@ 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 parser = argparse.ArgumentParser(description='Train or test neural net motor controller.') diff --git a/examples/reinforcement_learning/tutorial_DQN.py b/examples/reinforcement_learning/tutorial_DQN.py index d25120346..ce0086185 100644 --- a/examples/reinforcement_learning/tutorial_DQN.py +++ b/examples/reinforcement_learning/tutorial_DQN.py @@ -46,10 +46,10 @@ import argparse import time -import gym import numpy as np import tensorflow as tf +import gym import tensorlayer as tl # add arguments in command --train/test diff --git a/examples/reinforcement_learning/tutorial_PG.py b/examples/reinforcement_learning/tutorial_PG.py index c4f52dcb1..b32cdd434 100644 --- a/examples/reinforcement_learning/tutorial_PG.py +++ b/examples/reinforcement_learning/tutorial_PG.py @@ -30,11 +30,11 @@ 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 parser = argparse.ArgumentParser(description='Train or test neural net motor controller.') diff --git a/examples/reinforcement_learning/tutorial_PPO.py b/examples/reinforcement_learning/tutorial_PPO.py index 6091ff88e..8d7b2bd57 100644 --- a/examples/reinforcement_learning/tutorial_PPO.py +++ b/examples/reinforcement_learning/tutorial_PPO.py @@ -31,12 +31,12 @@ import os 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 parser = argparse.ArgumentParser(description='Train or test neural net motor controller.') diff --git a/examples/reinforcement_learning/tutorial_Qlearning.py b/examples/reinforcement_learning/tutorial_Qlearning.py index d11bade39..a8decb273 100644 --- a/examples/reinforcement_learning/tutorial_Qlearning.py +++ b/examples/reinforcement_learning/tutorial_Qlearning.py @@ -18,9 +18,10 @@ import time -import gym import numpy as np +import gym + ## Load the environment env = gym.make('FrozenLake-v0') render = False # display the game environment diff --git a/examples/reinforcement_learning/tutorial_SAC.py b/examples/reinforcement_learning/tutorial_SAC.py index 276f181bd..7facecb7b 100644 --- a/examples/reinforcement_learning/tutorial_SAC.py +++ b/examples/reinforcement_learning/tutorial_SAC.py @@ -35,18 +35,17 @@ ''' import argparse -import math import random import time -import gym import matplotlib.pyplot as plt import numpy as np import tensorflow as tf -import tensorflow_probability as tfp -from IPython.display import clear_output +import gym +import tensorflow_probability as tfp import tensorlayer as tl +from IPython.display import clear_output from tensorlayer.layers import Dense from tensorlayer.models import Model @@ -175,7 +174,7 @@ class PolicyNetwork(Model): ''' the network for generating non-determinstic (Gaussian distributed) action from the state input ''' def __init__( - self, num_inputs, num_actions, hidden_dim, action_range=1., init_w=3e-3, log_std_min=-20, log_std_max=2 + self, num_inputs, num_actions, hidden_dim, action_range=1., init_w=3e-3, log_std_min=-20, log_std_max=2 ): super(PolicyNetwork, self).__init__() diff --git a/examples/reinforcement_learning/tutorial_TD3.py b/examples/reinforcement_learning/tutorial_TD3.py index 3b7a16a0d..3c48d719e 100644 --- a/examples/reinforcement_learning/tutorial_TD3.py +++ b/examples/reinforcement_learning/tutorial_TD3.py @@ -41,18 +41,17 @@ ''' import argparse -import math import random import time -import gym import matplotlib.pyplot as plt import numpy as np import tensorflow as tf -import tensorflow_probability as tfp -from IPython.display import clear_output +import gym +import tensorflow_probability as tfp import tensorlayer as tl +from IPython.display import clear_output from tensorlayer.layers import Dense from tensorlayer.models import Model @@ -242,7 +241,7 @@ def sample_action(self, ): class TD3_Trainer(): def __init__( - self, replay_buffer, hidden_dim, action_range, policy_target_update_interval=1, q_lr=3e-4, policy_lr=3e-4 + self, replay_buffer, hidden_dim, action_range, policy_target_update_interval=1, q_lr=3e-4, policy_lr=3e-4 ): self.replay_buffer = replay_buffer diff --git a/examples/reinforcement_learning/tutorial_TRPO.py b/examples/reinforcement_learning/tutorial_TRPO.py index bf22ac685..b2ab1a5aa 100644 --- a/examples/reinforcement_learning/tutorial_TRPO.py +++ b/examples/reinforcement_learning/tutorial_TRPO.py @@ -33,15 +33,15 @@ import os import time -import gym import matplotlib.pyplot as plt import numpy as np import scipy.signal import tensorflow as tf -import tensorflow_probability as tfp -from gym.spaces import Box, Discrete +import gym +import tensorflow_probability as tfp import tensorlayer as tl +from gym.spaces import Box, Discrete parser = argparse.ArgumentParser(description='Train or test neural net motor controller.') parser.add_argument('--train', dest='train', action='store_true', default=True) @@ -335,8 +335,7 @@ def cal_outputs_1(self, states, actions, old_log_std_ph, old_mu_ph): def mlp_actor_critic( - x: 'env.observation_space', a: 'env.action_space', hidden_sizes=(64, 64), activation=tf.tanh, - output_activation=None + x: 'env.observation_space', a: 'env.action_space', hidden_sizes=(64, 64), activation=tf.tanh, output_activation=None ): """ create actor and critic diff --git a/examples/reinforcement_learning/tutorial_atari_pong.py b/examples/reinforcement_learning/tutorial_atari_pong.py index f4fb62cfd..97b535d7f 100644 --- a/examples/reinforcement_learning/tutorial_atari_pong.py +++ b/examples/reinforcement_learning/tutorial_atari_pong.py @@ -22,9 +22,9 @@ import time import numpy as np +import tensorflow as tf import gym -import tensorflow as tf import tensorlayer as tl tl.logging.set_verbosity(tl.logging.DEBUG) diff --git a/examples/reinforcement_learning/tutorial_wrappers.py b/examples/reinforcement_learning/tutorial_wrappers.py index c7395f063..a53e5102d 100644 --- a/examples/reinforcement_learning/tutorial_wrappers.py +++ b/examples/reinforcement_learning/tutorial_wrappers.py @@ -7,9 +7,10 @@ from multiprocessing import Pipe, Process, cpu_count from sys import platform +import numpy as np + import cv2 import gym -import numpy as np from gym import spaces __all__ = ( diff --git a/examples/text_word_embedding/tutorial_word2vec_basic.py b/examples/text_word_embedding/tutorial_word2vec_basic.py index 7ac9fdae1..d7bc63fbc 100644 --- a/examples/text_word_embedding/tutorial_word2vec_basic.py +++ b/examples/text_word_embedding/tutorial_word2vec_basic.py @@ -39,7 +39,6 @@ import argparse import os -import sys import time import numpy as np diff --git a/requirements/requirements_test.txt b/requirements/requirements_test.txt index e47c0ed72..9642a41a4 100644 --- a/requirements/requirements_test.txt +++ b/requirements/requirements_test.txt @@ -6,4 +6,6 @@ pytest-cache>=1.0,<1.1 pytest-cov>=2.7.1 pytest-xdist>=1.28.0 sphinx==2.0.1 -yapf>=0.27.0 +yapf==0.29.0 +autoflake==1.3.1 +isort==4.3.21 diff --git a/tensorlayer/cost.py b/tensorlayer/cost.py index 9c78509bc..9ccf5eeca 100644 --- a/tensorlayer/cost.py +++ b/tensorlayer/cost.py @@ -374,7 +374,7 @@ def iou_coe(output, target, threshold=0.5, axis=(1, 2, 3), smooth=1e-5): def sequence_loss_by_example( - logits, targets, weights, average_across_timesteps=True, softmax_loss_function=None, name=None + logits, targets, weights, average_across_timesteps=True, softmax_loss_function=None, name=None ): """Weighted cross-entropy loss for a sequence of logits (per example). see original tensorflow code : @@ -782,7 +782,7 @@ def mn_i(weights, name='maxnorm_i_regularizer'): def huber_loss( - output, target, is_mean=True, delta=1.0, dynamichuber=False, reverse=False, axis=-1, epsilon=0.00001, name=None + output, target, is_mean=True, delta=1.0, dynamichuber=False, reverse=False, axis=-1, epsilon=0.00001, name=None ): """Huber Loss operation, see ``https://en.wikipedia.org/wiki/Huber_loss`` . Reverse Huber Loss operation, see ''https://statweb.stanford.edu/~owen/reports/hhu.pdf''. diff --git a/tensorlayer/db.py b/tensorlayer/db.py index e37a863af..129e251e5 100644 --- a/tensorlayer/db.py +++ b/tensorlayer/db.py @@ -48,7 +48,7 @@ class TensorHub(object): # @deprecated_alias(db_name='dbname', user_name='username', end_support_version=2.1) def __init__( - self, ip='localhost', port=27017, dbname='dbname', username='None', password='password', project_name=None + self, ip='localhost', port=27017, dbname='dbname', username='None', password='password', project_name=None ): self.ip = ip self.port = port diff --git a/tensorlayer/distributed.py b/tensorlayer/distributed.py index 544aac87e..3b426f8f5 100644 --- a/tensorlayer/distributed.py +++ b/tensorlayer/distributed.py @@ -94,9 +94,9 @@ class Trainer(object): """ def __init__( - self, training_dataset, build_training_func, optimizer, optimizer_args, batch_size=32, prefetch_size=None, - checkpoint_dir=None, scaling_learning_rate=True, log_step_size=1, validation_dataset=None, - build_validation_func=None, max_iteration=float('inf') + self, training_dataset, build_training_func, optimizer, optimizer_args, batch_size=32, prefetch_size=None, + checkpoint_dir=None, scaling_learning_rate=True, log_step_size=1, validation_dataset=None, + build_validation_func=None, max_iteration=float('inf') ): # Initialize Horovod. hvd.init() @@ -395,9 +395,9 @@ def create_task_spec_def(): @deprecated(date="2018-10-30", instructions="Using the TensorLayer distributed trainer.") def create_distributed_session( - task_spec=None, checkpoint_dir=None, scaffold=None, hooks=None, chief_only_hooks=None, save_checkpoint_secs=600, - save_summaries_steps=object(), save_summaries_secs=object(), config=None, stop_grace_period_secs=120, - log_step_count_steps=100 + task_spec=None, checkpoint_dir=None, scaffold=None, hooks=None, chief_only_hooks=None, save_checkpoint_secs=600, + save_summaries_steps=object(), save_summaries_secs=object(), config=None, stop_grace_period_secs=120, + log_step_count_steps=100 ): """Creates a distributed session. diff --git a/tensorlayer/files/dataset_loaders/imdb_dataset.py b/tensorlayer/files/dataset_loaders/imdb_dataset.py index 34b4dffe0..2967e7ee6 100644 --- a/tensorlayer/files/dataset_loaders/imdb_dataset.py +++ b/tensorlayer/files/dataset_loaders/imdb_dataset.py @@ -13,8 +13,8 @@ def load_imdb_dataset( - path='data', nb_words=None, skip_top=0, maxlen=None, test_split=0.2, seed=113, start_char=1, oov_char=2, - index_from=3 + path='data', nb_words=None, skip_top=0, maxlen=None, test_split=0.2, seed=113, start_char=1, oov_char=2, + index_from=3 ): """Load IMDB dataset. diff --git a/tensorlayer/files/utils.py b/tensorlayer/files/utils.py index 4d71c8566..16793134f 100644 --- a/tensorlayer/files/utils.py +++ b/tensorlayer/files/utils.py @@ -839,8 +839,8 @@ def load_matt_mahoney_text8_dataset(path='data'): def load_imdb_dataset( - path='data', nb_words=None, skip_top=0, maxlen=None, test_split=0.2, seed=113, start_char=1, oov_char=2, - index_from=3 + path='data', nb_words=None, skip_top=0, maxlen=None, test_split=0.2, seed=113, start_char=1, oov_char=2, + index_from=3 ): """Load IMDB dataset. diff --git a/tensorlayer/layers/activation.py b/tensorlayer/layers/activation.py index e6d5d79f1..31abaeaba 100644 --- a/tensorlayer/layers/activation.py +++ b/tensorlayer/layers/activation.py @@ -54,11 +54,11 @@ class PRelu(Layer): """ def __init__( - self, - channel_shared=False, - in_channels=None, - a_init=truncated_normal(mean=0.0, stddev=0.05), - name=None # "prelu" + self, + channel_shared=False, + in_channels=None, + a_init=truncated_normal(mean=0.0, stddev=0.05), + name=None # "prelu" ): super(PRelu, self).__init__(name) @@ -141,11 +141,11 @@ class PRelu6(Layer): """ def __init__( - self, - channel_shared=False, - in_channels=None, - a_init=truncated_normal(mean=0.0, stddev=0.05), - name=None # "prelu6" + self, + channel_shared=False, + in_channels=None, + a_init=truncated_normal(mean=0.0, stddev=0.05), + name=None # "prelu6" ): super(PRelu6, self).__init__(name) @@ -229,11 +229,11 @@ class PTRelu6(Layer): """ def __init__( - self, - channel_shared=False, - in_channels=None, - a_init=truncated_normal(mean=0.0, stddev=0.05), - name=None # "ptrelu6" + self, + channel_shared=False, + in_channels=None, + a_init=truncated_normal(mean=0.0, stddev=0.05), + name=None # "ptrelu6" ): super(PTRelu6, self).__init__(name) diff --git a/tensorlayer/layers/convolution/binary_conv.py b/tensorlayer/layers/convolution/binary_conv.py index cf55127d5..92929ae92 100644 --- a/tensorlayer/layers/convolution/binary_conv.py +++ b/tensorlayer/layers/convolution/binary_conv.py @@ -61,19 +61,19 @@ class BinaryConv2d(Layer): """ def __init__( - self, - n_filter=32, - filter_size=(3, 3), - strides=(1, 1), - act=None, - padding='SAME', - use_gemm=False, - data_format="channels_last", - dilation_rate=(1, 1), - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None # 'binary_cnn2d', + self, + n_filter=32, + filter_size=(3, 3), + strides=(1, 1), + act=None, + padding='SAME', + use_gemm=False, + data_format="channels_last", + dilation_rate=(1, 1), + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None # 'binary_cnn2d', ): super().__init__(name, act=act) self.n_filter = n_filter diff --git a/tensorlayer/layers/convolution/deformable_conv.py b/tensorlayer/layers/convolution/deformable_conv.py index 032dd3a5f..3a8038c39 100644 --- a/tensorlayer/layers/convolution/deformable_conv.py +++ b/tensorlayer/layers/convolution/deformable_conv.py @@ -71,17 +71,17 @@ class DeformableConv2d(Layer): # @deprecated_alias(layer='prev_layer', end_support_version=1.9) # TODO remove this line for the 1.9 release def __init__( - self, - offset_layer=None, - # shape=(3, 3, 1, 100), - n_filter=32, - filter_size=(3, 3), - act=None, - padding='SAME', - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None # 'deformable_conv_2d', + self, + offset_layer=None, + # shape=(3, 3, 1, 100), + n_filter=32, + filter_size=(3, 3), + act=None, + padding='SAME', + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None # 'deformable_conv_2d', ): super().__init__(name, act=act) diff --git a/tensorlayer/layers/convolution/depthwise_conv.py b/tensorlayer/layers/convolution/depthwise_conv.py index b11233c27..4f963d317 100644 --- a/tensorlayer/layers/convolution/depthwise_conv.py +++ b/tensorlayer/layers/convolution/depthwise_conv.py @@ -69,18 +69,18 @@ class DepthwiseConv2d(Layer): # https://zhuanlan.zhihu.com/p/31551004 https://github.com/xiaohu2015/DeepLearning_tutorials/blob/master/CNNs/MobileNet.py def __init__( - self, - filter_size=(3, 3), - strides=(1, 1), - act=None, - padding='SAME', - data_format='channels_last', - dilation_rate=(1, 1), - depth_multiplier=1, - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None # 'depthwise_conv2d' + self, + filter_size=(3, 3), + strides=(1, 1), + act=None, + padding='SAME', + data_format='channels_last', + dilation_rate=(1, 1), + depth_multiplier=1, + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None # 'depthwise_conv2d' ): super().__init__(name, act=act) self.filter_size = filter_size diff --git a/tensorlayer/layers/convolution/dorefa_conv.py b/tensorlayer/layers/convolution/dorefa_conv.py index dc7979967..bc80f5e3a 100644 --- a/tensorlayer/layers/convolution/dorefa_conv.py +++ b/tensorlayer/layers/convolution/dorefa_conv.py @@ -65,21 +65,21 @@ class DorefaConv2d(Layer): """ def __init__( - self, - bitW=1, - bitA=3, - n_filter=32, - filter_size=(3, 3), - strides=(1, 1), - act=None, - padding='SAME', - use_gemm=False, - data_format="channels_last", - dilation_rate=(1, 1), - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None # 'dorefa_cnn2d', + self, + bitW=1, + bitA=3, + n_filter=32, + filter_size=(3, 3), + strides=(1, 1), + act=None, + padding='SAME', + use_gemm=False, + data_format="channels_last", + dilation_rate=(1, 1), + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None # 'dorefa_cnn2d', ): super().__init__(name, act=act) self.bitW = bitW diff --git a/tensorlayer/layers/convolution/expert_conv.py b/tensorlayer/layers/convolution/expert_conv.py index 50ea12cb9..062a2738c 100644 --- a/tensorlayer/layers/convolution/expert_conv.py +++ b/tensorlayer/layers/convolution/expert_conv.py @@ -60,16 +60,16 @@ class Conv1dLayer(Layer): """ def __init__( - self, - act=None, - shape=(5, 1, 5), - stride=1, - padding='SAME', - data_format='NWC', - dilation_rate=1, - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - name=None # 'cnn1d_layer', + self, + act=None, + shape=(5, 1, 5), + stride=1, + padding='SAME', + data_format='NWC', + dilation_rate=1, + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + name=None # 'cnn1d_layer', ): super().__init__(name, act=act) self.n_filter = shape[-1] @@ -179,16 +179,16 @@ class Conv2dLayer(Layer): """ def __init__( - self, - act=None, - shape=(5, 5, 1, 100), - strides=(1, 1, 1, 1), - padding='SAME', - data_format='NHWC', - dilation_rate=(1, 1, 1, 1), - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - name=None # 'cnn2d_layer', + self, + act=None, + shape=(5, 5, 1, 100), + strides=(1, 1, 1, 1), + padding='SAME', + data_format='NHWC', + dilation_rate=(1, 1, 1, 1), + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + name=None # 'cnn2d_layer', ): super().__init__(name, act=act) self.n_filter = shape[-1] @@ -297,16 +297,16 @@ class Conv3dLayer(Layer): """ def __init__( - self, - act=None, - shape=(2, 2, 2, 3, 32), - strides=(1, 2, 2, 2, 1), - padding='SAME', - data_format='NDHWC', - dilation_rate=(1, 1, 1, 1, 1), - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - name=None # 'cnn3d_layer' + self, + act=None, + shape=(2, 2, 2, 3, 32), + strides=(1, 2, 2, 2, 1), + padding='SAME', + data_format='NDHWC', + dilation_rate=(1, 1, 1, 1, 1), + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + name=None # 'cnn3d_layer' ): super().__init__(name, act=act) self.n_filter = shape[-1] diff --git a/tensorlayer/layers/convolution/expert_deconv.py b/tensorlayer/layers/convolution/expert_deconv.py index f23c752ad..ace1f221b 100644 --- a/tensorlayer/layers/convolution/expert_deconv.py +++ b/tensorlayer/layers/convolution/expert_deconv.py @@ -68,17 +68,17 @@ class DeConv1dLayer(Layer): """ def __init__( - self, - act=None, - shape=(3, 128, 256), - outputs_shape=(1, 256, 128), - strides=(1, 2, 1), - padding='SAME', - data_format='NWC', - dilation_rate=(1, 1, 1), - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - name=None # 'decnn1d_layer', + self, + act=None, + shape=(3, 128, 256), + outputs_shape=(1, 256, 128), + strides=(1, 2, 1), + padding='SAME', + data_format='NWC', + dilation_rate=(1, 1, 1), + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + name=None # 'decnn1d_layer', ): super().__init__(name, act=act) self.shape = shape @@ -202,17 +202,17 @@ class DeConv2dLayer(Layer): """ def __init__( - self, - act=None, - shape=(3, 3, 128, 256), - outputs_shape=(1, 256, 256, 128), - strides=(1, 2, 2, 1), - padding='SAME', - data_format='NHWC', - dilation_rate=(1, 1, 1, 1), - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - name=None # 'decnn2d_layer', + self, + act=None, + shape=(3, 3, 128, 256), + outputs_shape=(1, 256, 256, 128), + strides=(1, 2, 2, 1), + padding='SAME', + data_format='NHWC', + dilation_rate=(1, 1, 1, 1), + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + name=None # 'decnn2d_layer', ): super().__init__(name, act=act) self.shape = shape @@ -328,17 +328,17 @@ class DeConv3dLayer(Layer): """ def __init__( - self, - act=None, - shape=(2, 2, 2, 128, 256), - outputs_shape=(1, 12, 32, 32, 128), - strides=(1, 2, 2, 2, 1), - padding='SAME', - data_format='NDHWC', - dilation_rate=(1, 1, 1, 1, 1), - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - name=None # 'decnn3d_layer', + self, + act=None, + shape=(2, 2, 2, 128, 256), + outputs_shape=(1, 12, 32, 32, 128), + strides=(1, 2, 2, 2, 1), + padding='SAME', + data_format='NDHWC', + dilation_rate=(1, 1, 1, 1, 1), + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + name=None # 'decnn3d_layer', ): super().__init__(name, act=act) self.shape = shape diff --git a/tensorlayer/layers/convolution/group_conv.py b/tensorlayer/layers/convolution/group_conv.py index bc35d4e00..78b7b17fa 100644 --- a/tensorlayer/layers/convolution/group_conv.py +++ b/tensorlayer/layers/convolution/group_conv.py @@ -59,19 +59,19 @@ class GroupConv2d(Layer): """ def __init__( - self, - n_filter=32, - filter_size=(3, 3), - strides=(2, 2), - n_group=2, - act=None, - padding='SAME', - data_format='channels_last', - dilation_rate=(1, 1), - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None # 'groupconv', + self, + n_filter=32, + filter_size=(3, 3), + strides=(2, 2), + n_group=2, + act=None, + padding='SAME', + data_format='channels_last', + dilation_rate=(1, 1), + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None # 'groupconv', ): # Windaway super().__init__(name, act=act) self.n_filter = n_filter diff --git a/tensorlayer/layers/convolution/quan_conv.py b/tensorlayer/layers/convolution/quan_conv.py index 75ee3943c..6d17376c8 100644 --- a/tensorlayer/layers/convolution/quan_conv.py +++ b/tensorlayer/layers/convolution/quan_conv.py @@ -66,21 +66,21 @@ class QuanConv2d(Layer): """ def __init__( - self, - bitW=8, - bitA=8, - n_filter=32, - filter_size=(3, 3), - strides=(1, 1), - act=None, - padding='SAME', - use_gemm=False, - data_format="channels_last", - dilation_rate=(1, 1), - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None # 'quan_cnn2d', + self, + bitW=8, + bitA=8, + n_filter=32, + filter_size=(3, 3), + strides=(1, 1), + act=None, + padding='SAME', + use_gemm=False, + data_format="channels_last", + dilation_rate=(1, 1), + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None # 'quan_cnn2d', ): super().__init__(name, act=act) self.bitW = bitW diff --git a/tensorlayer/layers/convolution/quan_conv_bn.py b/tensorlayer/layers/convolution/quan_conv_bn.py index ef0f9bfda..02bf8705d 100644 --- a/tensorlayer/layers/convolution/quan_conv_bn.py +++ b/tensorlayer/layers/convolution/quan_conv_bn.py @@ -92,26 +92,26 @@ class QuanConv2dWithBN(Layer): @deprecated_alias(layer='prev_layer', end_support_version=1.9) # TODO remove this line for the 1.9 release def __init__( - self, - prev_layer, - n_filter=32, - filter_size=(3, 3), - strides=(1, 1), - padding='SAME', - act=None, - decay=0.9, - epsilon=1e-5, - is_train=False, - gamma_init=tf.compat.v1.initializers.ones, - beta_init=tf.compat.v1.initializers.zeros, - bitW=8, - bitA=8, - use_gemm=False, - W_init=tf.compat.v1.initializers.truncated_normal(stddev=0.02), - W_init_args=None, - use_cudnn_on_gpu=None, - data_format=None, - name='quan_cnn2d_bn', + self, + prev_layer, + n_filter=32, + filter_size=(3, 3), + strides=(1, 1), + padding='SAME', + act=None, + decay=0.9, + epsilon=1e-5, + is_train=False, + gamma_init=tf.compat.v1.initializers.ones, + beta_init=tf.compat.v1.initializers.zeros, + bitW=8, + bitA=8, + use_gemm=False, + W_init=tf.compat.v1.initializers.truncated_normal(stddev=0.02), + W_init_args=None, + use_cudnn_on_gpu=None, + data_format=None, + name='quan_cnn2d_bn', ): super(QuanConv2dWithBN, self).__init__(prev_layer=prev_layer, act=act, W_init_args=W_init_args, name=name) diff --git a/tensorlayer/layers/convolution/separable_conv.py b/tensorlayer/layers/convolution/separable_conv.py index ca1c66d49..156a5f80d 100644 --- a/tensorlayer/layers/convolution/separable_conv.py +++ b/tensorlayer/layers/convolution/separable_conv.py @@ -61,28 +61,28 @@ class SeparableConv1d(Layer): # @deprecated_alias(layer='prev_layer', end_support_version=1.9) # TODO remove this line for the 1.9 release def __init__( - self, - n_filter=100, - filter_size=3, - strides=1, - act=None, - padding='valid', - data_format='channels_last', - dilation_rate=1, - depth_multiplier=1, - depthwise_init=None, - pointwise_init=None, - b_init=tl.initializers.constant(value=0.0), - # depthwise_regularizer=None, - # pointwise_regularizer=None, - # bias_regularizer=None, - # activity_regularizer=None, - # depthwise_constraint=None, - # pointwise_constraint=None, - # W_init=tf.truncated_normal_initializer(stddev=0.1), - # b_init=tf.constant_initializer(value=0.0), - in_channels=None, - name=None # 'seperable1d', + self, + n_filter=100, + filter_size=3, + strides=1, + act=None, + padding='valid', + data_format='channels_last', + dilation_rate=1, + depth_multiplier=1, + depthwise_init=None, + pointwise_init=None, + b_init=tl.initializers.constant(value=0.0), + # depthwise_regularizer=None, + # pointwise_regularizer=None, + # bias_regularizer=None, + # activity_regularizer=None, + # depthwise_constraint=None, + # pointwise_constraint=None, + # W_init=tf.truncated_normal_initializer(stddev=0.1), + # b_init=tf.constant_initializer(value=0.0), + in_channels=None, + name=None # 'seperable1d', ): super().__init__(name, act=act) self.n_filter = n_filter @@ -208,28 +208,28 @@ class SeparableConv2d(Layer): # @deprecated_alias(layer='prev_layer', end_support_version=1.9) # TODO remove this line for the 1.9 release def __init__( - self, - n_filter=100, - filter_size=(3, 3), - strides=(1, 1), - act=None, - padding='valid', - data_format='channels_last', - dilation_rate=(1, 1), - depth_multiplier=1, - depthwise_init=None, - pointwise_init=None, - b_init=tl.initializers.constant(value=0.0), - # depthwise_regularizer=None, - # pointwise_regularizer=None, - # bias_regularizer=None, - # activity_regularizer=None, - # depthwise_constraint=None, - # pointwise_constraint=None, - # W_init=tf.truncated_normal_initializer(stddev=0.1), - # b_init=tf.constant_initializer(value=0.0), - in_channels=None, - name=None # 'seperable2d', + self, + n_filter=100, + filter_size=(3, 3), + strides=(1, 1), + act=None, + padding='valid', + data_format='channels_last', + dilation_rate=(1, 1), + depth_multiplier=1, + depthwise_init=None, + pointwise_init=None, + b_init=tl.initializers.constant(value=0.0), + # depthwise_regularizer=None, + # pointwise_regularizer=None, + # bias_regularizer=None, + # activity_regularizer=None, + # depthwise_constraint=None, + # pointwise_constraint=None, + # W_init=tf.truncated_normal_initializer(stddev=0.1), + # b_init=tf.constant_initializer(value=0.0), + in_channels=None, + name=None # 'seperable2d', ): super().__init__(name, act=act) self.n_filter = n_filter diff --git a/tensorlayer/layers/convolution/simplified_conv.py b/tensorlayer/layers/convolution/simplified_conv.py index 6975a4223..fab3d5817 100644 --- a/tensorlayer/layers/convolution/simplified_conv.py +++ b/tensorlayer/layers/convolution/simplified_conv.py @@ -57,18 +57,18 @@ class Conv1d(Layer): """ def __init__( - self, - n_filter=32, - filter_size=5, - stride=1, - act=None, - padding='SAME', - data_format="channels_last", - dilation_rate=1, - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None # 'conv1d' + self, + n_filter=32, + filter_size=5, + stride=1, + act=None, + padding='SAME', + data_format="channels_last", + dilation_rate=1, + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None # 'conv1d' ): super().__init__(name, act=act) self.n_filter = n_filter @@ -187,18 +187,18 @@ class Conv2d(Layer): """ def __init__( - self, - n_filter=32, - filter_size=(3, 3), - strides=(1, 1), - act=None, - padding='SAME', - data_format='channels_last', - dilation_rate=(1, 1), - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None # 'conv2d', + self, + n_filter=32, + filter_size=(3, 3), + strides=(1, 1), + act=None, + padding='SAME', + data_format='channels_last', + dilation_rate=(1, 1), + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None # 'conv2d', ): super().__init__(name, act=act) self.n_filter = n_filter @@ -320,18 +320,18 @@ class Conv3d(Layer): """ def __init__( - self, - n_filter=32, - filter_size=(3, 3, 3), - strides=(1, 1, 1), - act=None, - padding='SAME', - data_format='channels_last', - dilation_rate=(1, 1, 1), - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None # 'conv3d', + self, + n_filter=32, + filter_size=(3, 3, 3), + strides=(1, 1, 1), + act=None, + padding='SAME', + data_format='channels_last', + dilation_rate=(1, 1, 1), + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None # 'conv3d', ): super().__init__(name, act=act) self.n_filter = n_filter diff --git a/tensorlayer/layers/convolution/simplified_deconv.py b/tensorlayer/layers/convolution/simplified_deconv.py index 57beff0f4..282356b69 100644 --- a/tensorlayer/layers/convolution/simplified_deconv.py +++ b/tensorlayer/layers/convolution/simplified_deconv.py @@ -58,18 +58,18 @@ class DeConv2d(Layer): """ def __init__( - self, - n_filter=32, - filter_size=(3, 3), - strides=(2, 2), - act=None, - padding='SAME', - dilation_rate=(1, 1), - data_format='channels_last', - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None # 'decnn2d' + self, + n_filter=32, + filter_size=(3, 3), + strides=(2, 2), + act=None, + padding='SAME', + dilation_rate=(1, 1), + data_format='channels_last', + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None # 'decnn2d' ): super().__init__(name, act=act) self.n_filter = n_filter @@ -186,17 +186,17 @@ class DeConv3d(Layer): """ def __init__( - self, - n_filter=32, - filter_size=(3, 3, 3), - strides=(2, 2, 2), - padding='SAME', - act=None, - data_format='channels_last', - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None # 'decnn3d' + self, + n_filter=32, + filter_size=(3, 3, 3), + strides=(2, 2, 2), + padding='SAME', + act=None, + data_format='channels_last', + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None # 'decnn3d' ): super().__init__(name, act=act) self.n_filter = n_filter diff --git a/tensorlayer/layers/convolution/super_resolution.py b/tensorlayer/layers/convolution/super_resolution.py index 4481b13ab..5bdbd24c7 100644 --- a/tensorlayer/layers/convolution/super_resolution.py +++ b/tensorlayer/layers/convolution/super_resolution.py @@ -47,11 +47,11 @@ class SubpixelConv1d(Layer): """ def __init__( - self, - scale=2, - act=None, - in_channels=None, - name=None # 'subpixel_conv1d' + self, + scale=2, + act=None, + in_channels=None, + name=None # 'subpixel_conv1d' ): super().__init__(name, act=act) self.scale = scale @@ -80,7 +80,6 @@ def build(self, inputs_shape): if inputs_shape is not None: self.in_channels = inputs_shape[-1] self.out_channels = int(self.in_channels / self.scale) - pass def forward(self, inputs): outputs = self._PS(inputs, r=self.scale) @@ -142,12 +141,12 @@ class SubpixelConv2d(Layer): # github/Tetrachrome/subpixel https://github.com/Tetrachrome/subpixel/blob/master/subpixel.py def __init__( - self, - scale=2, - n_out_channels=None, - act=None, - in_channels=None, - name=None # 'subpixel_conv2d' + self, + scale=2, + n_out_channels=None, + act=None, + in_channels=None, + name=None # 'subpixel_conv2d' ): super().__init__(name, act=act) self.scale = scale diff --git a/tensorlayer/layers/convolution/ternary_conv.py b/tensorlayer/layers/convolution/ternary_conv.py index 33e01507c..a75630a9f 100644 --- a/tensorlayer/layers/convolution/ternary_conv.py +++ b/tensorlayer/layers/convolution/ternary_conv.py @@ -61,19 +61,19 @@ class TernaryConv2d(Layer): """ def __init__( - self, - n_filter=32, - filter_size=(3, 3), - strides=(1, 1), - act=None, - padding='SAME', - use_gemm=False, - data_format="channels_last", - dilation_rate=(1, 1), - W_init=tl.initializers.truncated_normal(stddev=0.02), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None # 'ternary_cnn2d', + self, + n_filter=32, + filter_size=(3, 3), + strides=(1, 1), + act=None, + padding='SAME', + use_gemm=False, + data_format="channels_last", + dilation_rate=(1, 1), + W_init=tl.initializers.truncated_normal(stddev=0.02), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None # 'ternary_cnn2d', ): super().__init__(name, act=act) self.n_filter = n_filter diff --git a/tensorlayer/layers/dense/base_dense.py b/tensorlayer/layers/dense/base_dense.py index 4f3301b2a..c24080432 100644 --- a/tensorlayer/layers/dense/base_dense.py +++ b/tensorlayer/layers/dense/base_dense.py @@ -54,13 +54,13 @@ class Dense(Layer): """ def __init__( - self, - n_units, - act=None, - W_init=tl.initializers.truncated_normal(stddev=0.05), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None, # 'dense', + self, + n_units, + act=None, + W_init=tl.initializers.truncated_normal(stddev=0.05), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None, # 'dense', ): super(Dense, self).__init__(name, act=act) diff --git a/tensorlayer/layers/dense/binary_dense.py b/tensorlayer/layers/dense/binary_dense.py index a609cf5cf..d4d152ac0 100644 --- a/tensorlayer/layers/dense/binary_dense.py +++ b/tensorlayer/layers/dense/binary_dense.py @@ -40,14 +40,14 @@ class BinaryDense(Layer): """ def __init__( - self, - n_units=100, - act=None, - use_gemm=False, - W_init=tl.initializers.truncated_normal(stddev=0.05), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None, #'binary_dense', + self, + n_units=100, + act=None, + use_gemm=False, + W_init=tl.initializers.truncated_normal(stddev=0.05), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None, #'binary_dense', ): super().__init__(name, act=act) self.n_units = n_units diff --git a/tensorlayer/layers/dense/dorefa_dense.py b/tensorlayer/layers/dense/dorefa_dense.py index b6a5dfa1c..4bc4f40df 100644 --- a/tensorlayer/layers/dense/dorefa_dense.py +++ b/tensorlayer/layers/dense/dorefa_dense.py @@ -45,16 +45,16 @@ class DorefaDense(Layer): """ def __init__( - self, - bitW=1, - bitA=3, - n_units=100, - act=None, - use_gemm=False, - W_init=tl.initializers.truncated_normal(stddev=0.05), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None, #'dorefa_dense', + self, + bitW=1, + bitA=3, + n_units=100, + act=None, + use_gemm=False, + W_init=tl.initializers.truncated_normal(stddev=0.05), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None, #'dorefa_dense', ): super().__init__(name, act=act) self.bitW = bitW diff --git a/tensorlayer/layers/dense/dropconnect.py b/tensorlayer/layers/dense/dropconnect.py index ee40d8665..43c3a144a 100644 --- a/tensorlayer/layers/dense/dropconnect.py +++ b/tensorlayer/layers/dense/dropconnect.py @@ -57,14 +57,14 @@ class DropconnectDense(Layer): """ def __init__( - self, - keep=0.5, - n_units=100, - act=None, - W_init=tl.initializers.truncated_normal(stddev=0.05), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None, # 'dropconnect', + self, + keep=0.5, + n_units=100, + act=None, + W_init=tl.initializers.truncated_normal(stddev=0.05), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None, # 'dropconnect', ): super().__init__(name, act=act) diff --git a/tensorlayer/layers/dense/quan_dense.py b/tensorlayer/layers/dense/quan_dense.py index b1c427fdc..67ca73074 100644 --- a/tensorlayer/layers/dense/quan_dense.py +++ b/tensorlayer/layers/dense/quan_dense.py @@ -43,16 +43,16 @@ class QuanDense(Layer): """ def __init__( - self, - n_units=100, - act=None, - bitW=8, - bitA=8, - use_gemm=False, - W_init=tl.initializers.truncated_normal(stddev=0.05), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None, #'quan_dense', + self, + n_units=100, + act=None, + bitW=8, + bitA=8, + use_gemm=False, + W_init=tl.initializers.truncated_normal(stddev=0.05), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None, #'quan_dense', ): super().__init__(name, act=act) self.n_units = n_units diff --git a/tensorlayer/layers/dense/quan_dense_bn.py b/tensorlayer/layers/dense/quan_dense_bn.py index 647b08848..52abefd0b 100644 --- a/tensorlayer/layers/dense/quan_dense_bn.py +++ b/tensorlayer/layers/dense/quan_dense_bn.py @@ -68,21 +68,21 @@ class QuanDenseLayerWithBN(Layer): @deprecated_alias(layer='prev_layer', end_support_version=1.9) # TODO remove this line for the 1.9 release def __init__( - self, - prev_layer, - n_units=100, - act=None, - decay=0.9, - epsilon=1e-5, - is_train=False, - bitW=8, - bitA=8, - gamma_init=tf.compat.v1.initializers.ones, - beta_init=tf.compat.v1.initializers.zeros, - use_gemm=False, - W_init=tf.compat.v1.initializers.truncated_normal(stddev=0.05), - W_init_args=None, - name=None, #'quan_dense_with_bn', + self, + prev_layer, + n_units=100, + act=None, + decay=0.9, + epsilon=1e-5, + is_train=False, + bitW=8, + bitA=8, + gamma_init=tf.compat.v1.initializers.ones, + beta_init=tf.compat.v1.initializers.zeros, + use_gemm=False, + W_init=tf.compat.v1.initializers.truncated_normal(stddev=0.05), + W_init_args=None, + name=None, #'quan_dense_with_bn', ): super(QuanDenseLayerWithBN, self).__init__(prev_layer=prev_layer, act=act, W_init_args=W_init_args, name=name) diff --git a/tensorlayer/layers/dense/ternary_dense.py b/tensorlayer/layers/dense/ternary_dense.py index 0bb343285..49479df7c 100644 --- a/tensorlayer/layers/dense/ternary_dense.py +++ b/tensorlayer/layers/dense/ternary_dense.py @@ -40,14 +40,14 @@ class TernaryDense(Layer): """ def __init__( - self, - n_units=100, - act=None, - use_gemm=False, - W_init=tl.initializers.truncated_normal(stddev=0.05), - b_init=tl.initializers.constant(value=0.0), - in_channels=None, - name=None, #'ternary_dense', + self, + n_units=100, + act=None, + use_gemm=False, + W_init=tl.initializers.truncated_normal(stddev=0.05), + b_init=tl.initializers.constant(value=0.0), + in_channels=None, + name=None, #'ternary_dense', ): super().__init__(name, act=act) self.n_units = n_units diff --git a/tensorlayer/layers/embedding.py b/tensorlayer/layers/embedding.py index 80c5cadfa..861723c38 100644 --- a/tensorlayer/layers/embedding.py +++ b/tensorlayer/layers/embedding.py @@ -186,16 +186,16 @@ class Word2vecEmbedding(Layer): """ def __init__( - self, - vocabulary_size, - embedding_size, - num_sampled=64, - activate_nce_loss=True, - nce_loss_args=None, - E_init=tl.initializers.random_uniform(minval=-1.0, maxval=1.0), - nce_W_init=tl.initializers.truncated_normal(stddev=0.03), - nce_b_init=tl.initializers.constant(value=0.0), - name=None, #'word2vec', + self, + vocabulary_size, + embedding_size, + num_sampled=64, + activate_nce_loss=True, + nce_loss_args=None, + E_init=tl.initializers.random_uniform(minval=-1.0, maxval=1.0), + nce_W_init=tl.initializers.truncated_normal(stddev=0.03), + nce_b_init=tl.initializers.constant(value=0.0), + name=None, #'word2vec', ): super(Word2vecEmbedding, self).__init__(name) @@ -352,11 +352,11 @@ class Embedding(Layer): """ def __init__( - self, - vocabulary_size, - embedding_size, - E_init=tl.initializers.random_uniform(-0.1, 0.1), - name=None, #'embedding', + self, + vocabulary_size, + embedding_size, + E_init=tl.initializers.random_uniform(-0.1, 0.1), + name=None, #'embedding', ): super(Embedding, self).__init__(name) self.vocabulary_size = vocabulary_size @@ -446,12 +446,12 @@ class AverageEmbedding(Layer): """ def __init__( - self, - vocabulary_size, - embedding_size, - pad_value=0, - E_init=tl.initializers.random_uniform(-0.1, 0.1), - name=None, # 'average_embedding', + self, + vocabulary_size, + embedding_size, + pad_value=0, + E_init=tl.initializers.random_uniform(-0.1, 0.1), + name=None, # 'average_embedding', ): super(AverageEmbedding, self).__init__(name) diff --git a/tensorlayer/layers/extend.py b/tensorlayer/layers/extend.py index 42395a537..c34815e97 100644 --- a/tensorlayer/layers/extend.py +++ b/tensorlayer/layers/extend.py @@ -33,9 +33,9 @@ class ExpandDims(Layer): """ def __init__( - self, - axis, - name=None # 'expand_dims', + self, + axis, + name=None # 'expand_dims', ): super(ExpandDims, self).__init__(name) self.axis = axis diff --git a/tensorlayer/layers/image_resampling.py b/tensorlayer/layers/image_resampling.py index 22bde8386..b327901a7 100644 --- a/tensorlayer/layers/image_resampling.py +++ b/tensorlayer/layers/image_resampling.py @@ -46,12 +46,12 @@ class UpSampling2d(Layer): """ def __init__( - self, - scale, - method='bilinear', - antialias=False, - data_format='channel_last', - name=None, + self, + scale, + method='bilinear', + antialias=False, + data_format='channel_last', + name=None, ): super(UpSampling2d, self).__init__(name) self.method = method @@ -127,12 +127,12 @@ class DownSampling2d(Layer): """ def __init__( - self, - scale, - method='bilinear', - antialias=False, - data_format='channel_last', - name=None, + self, + scale, + method='bilinear', + antialias=False, + data_format='channel_last', + name=None, ): super(DownSampling2d, self).__init__(name) self.method = method diff --git a/tensorlayer/layers/lambda_layers.py b/tensorlayer/layers/lambda_layers.py index db9b9d685..c650f233c 100644 --- a/tensorlayer/layers/lambda_layers.py +++ b/tensorlayer/layers/lambda_layers.py @@ -102,11 +102,11 @@ class Lambda(Layer): """ def __init__( - self, - fn, - fn_weights=None, - fn_args=None, - name=None, + self, + fn, + fn_weights=None, + fn_args=None, + name=None, ): super(Lambda, self).__init__(name=name) @@ -224,11 +224,11 @@ class ElementwiseLambda(Layer): """ def __init__( - self, - fn, - fn_weights=None, - fn_args=None, - name=None, #'elementwiselambda', + self, + fn, + fn_weights=None, + fn_args=None, + name=None, #'elementwiselambda', ): super(ElementwiseLambda, self).__init__(name=name) diff --git a/tensorlayer/layers/merge.py b/tensorlayer/layers/merge.py index 6f49374ca..3191d9db1 100644 --- a/tensorlayer/layers/merge.py +++ b/tensorlayer/layers/merge.py @@ -40,9 +40,9 @@ class Concat(Layer): """ def __init__( - self, - concat_dim=-1, - name=None, #'concat', + self, + concat_dim=-1, + name=None, #'concat', ): super(Concat, self).__init__(name) @@ -105,10 +105,10 @@ class Elementwise(Layer): """ def __init__( - self, - combine_fn=tf.minimum, - act=None, - name=None, #'elementwise', + self, + combine_fn=tf.minimum, + act=None, + name=None, #'elementwise', ): super(Elementwise, self).__init__(name, act=act) diff --git a/tensorlayer/layers/noise.py b/tensorlayer/layers/noise.py index a57aea71e..1a6e85463 100644 --- a/tensorlayer/layers/noise.py +++ b/tensorlayer/layers/noise.py @@ -44,12 +44,12 @@ class GaussianNoise(Layer): """ def __init__( - self, - mean=0.0, - stddev=1.0, - is_always=True, - seed=None, - name=None, # 'gaussian_noise', + self, + mean=0.0, + stddev=1.0, + is_always=True, + seed=None, + name=None, # 'gaussian_noise', ): super().__init__(name) self.mean = mean diff --git a/tensorlayer/layers/normalization.py b/tensorlayer/layers/normalization.py index 744714eee..79400071b 100644 --- a/tensorlayer/layers/normalization.py +++ b/tensorlayer/layers/normalization.py @@ -48,12 +48,12 @@ class LocalResponseNorm(Layer): """ def __init__( - self, - depth_radius=None, - bias=None, - alpha=None, - beta=None, - name=None, #'lrn', + self, + depth_radius=None, + bias=None, + alpha=None, + beta=None, + name=None, #'lrn', ): # super(LocalResponseNorm, self).__init__(prev_layer=prev_layer, name=name) super().__init__(name) @@ -195,18 +195,18 @@ class BatchNorm(Layer): """ def __init__( - self, - decay=0.9, - epsilon=0.00001, - act=None, - is_train=False, - beta_init=tl.initializers.zeros(), - gamma_init=tl.initializers.random_normal(mean=1.0, stddev=0.002), - moving_mean_init=tl.initializers.zeros(), - moving_var_init=tl.initializers.zeros(), - num_features=None, - data_format='channels_last', - name=None, + self, + decay=0.9, + epsilon=0.00001, + act=None, + is_train=False, + beta_init=tl.initializers.zeros(), + gamma_init=tl.initializers.random_normal(mean=1.0, stddev=0.002), + moving_mean_init=tl.initializers.zeros(), + moving_var_init=tl.initializers.zeros(), + num_features=None, + data_format='channels_last', + name=None, ): super(BatchNorm, self).__init__(name=name, act=act) self.decay = decay @@ -411,9 +411,9 @@ class InstanceNorm(Layer): """ def __init__( - self, act=None, epsilon=0.00001, beta_init=tl.initializers.zeros(), - gamma_init=tl.initializers.random_normal(mean=1.0, stddev=0.002), num_features=None, - data_format='channels_last', name=None + self, act=None, epsilon=0.00001, beta_init=tl.initializers.zeros(), + gamma_init=tl.initializers.random_normal(mean=1.0, stddev=0.002), num_features=None, + data_format='channels_last', name=None ): super(InstanceNorm, self).__init__(name=name, act=act) self.epsilon = epsilon @@ -606,21 +606,21 @@ class LayerNorm(Layer): """ def __init__( - self, #prev_layer, - center=True, - scale=True, - act=None, - # reuse=None, - # variables_collections=None, - # outputs_collections=None, - # trainable=True, - epsilon=1e-12, - begin_norm_axis=1, - begin_params_axis=-1, - beta_init=tl.initializers.zeros(), - gamma_init=tl.initializers.ones(), - data_format='channels_last', - name=None, + self, #prev_layer, + center=True, + scale=True, + act=None, + # reuse=None, + # variables_collections=None, + # outputs_collections=None, + # trainable=True, + epsilon=1e-12, + begin_norm_axis=1, + begin_params_axis=-1, + beta_init=tl.initializers.zeros(), + gamma_init=tl.initializers.ones(), + data_format='channels_last', + name=None, ): # super(LayerNorm, self).__init__(prev_layer=prev_layer, act=act, name=name) @@ -805,17 +805,17 @@ class SwitchNorm(Layer): """ def __init__( - self, - act=None, - epsilon=1e-5, - beta_init=tl.initializers.constant(0.0), - gamma_init=tl.initializers.constant(1.0), - moving_mean_init=tl.initializers.zeros(), - # beta_init=tf.compat.v1.initializers.constant(0.0), - # gamma_init=tf.compat.v1.initializers.constant(1.0), - # moving_mean_init=tf.compat.v1.initializers.zeros(), - data_format='channels_last', - name=None, #'switchnorm', + self, + act=None, + epsilon=1e-5, + beta_init=tl.initializers.constant(0.0), + gamma_init=tl.initializers.constant(1.0), + moving_mean_init=tl.initializers.zeros(), + # beta_init=tf.compat.v1.initializers.constant(0.0), + # gamma_init=tf.compat.v1.initializers.constant(1.0), + # moving_mean_init=tf.compat.v1.initializers.zeros(), + data_format='channels_last', + name=None, #'switchnorm', ): # super(SwitchNorm, self).__init__(prev_layer=prev_layer, act=act, name=name) super().__init__(name, act=act) diff --git a/tensorlayer/layers/padding.py b/tensorlayer/layers/padding.py index db1bbb304..ae89035bc 100644 --- a/tensorlayer/layers/padding.py +++ b/tensorlayer/layers/padding.py @@ -41,10 +41,10 @@ class PadLayer(Layer): """ def __init__( - self, - padding=None, - mode='CONSTANT', - name=None, # 'pad_layer', + self, + padding=None, + mode='CONSTANT', + name=None, # 'pad_layer', ): super().__init__(name) self.padding = padding @@ -99,9 +99,9 @@ class ZeroPad1d(Layer): """ def __init__( - self, - padding, - name=None, # 'zeropad1d', + self, + padding, + name=None, # 'zeropad1d', ): super().__init__(name) self.padding = padding @@ -153,9 +153,9 @@ class ZeroPad2d(Layer): """ def __init__( - self, - padding, - name=None, # 'zeropad2d', + self, + padding, + name=None, # 'zeropad2d', ): super().__init__(name) @@ -208,9 +208,9 @@ class ZeroPad3d(Layer): """ def __init__( - self, - padding, - name=None, # 'zeropad3d', + self, + padding, + name=None, # 'zeropad3d', ): super().__init__(name) self.padding = padding diff --git a/tensorlayer/layers/pooling.py b/tensorlayer/layers/pooling.py index 2046de6c5..efcfb2763 100644 --- a/tensorlayer/layers/pooling.py +++ b/tensorlayer/layers/pooling.py @@ -59,12 +59,12 @@ class PoolLayer(Layer): """ def __init__( - self, - filter_size=(1, 2, 2, 1), - strides=(1, 2, 2, 1), - padding='SAME', - pool=tf.nn.max_pool, - name=None # 'pool_pro', + self, + filter_size=(1, 2, 2, 1), + strides=(1, 2, 2, 1), + padding='SAME', + pool=tf.nn.max_pool, + name=None # 'pool_pro', ): super().__init__(name) self.filter_size = filter_size @@ -122,13 +122,13 @@ class MaxPool1d(Layer): """ def __init__( - self, - filter_size=3, - strides=2, - padding='SAME', - data_format='channels_last', - dilation_rate=1, - name=None # 'maxpool1d' + self, + filter_size=3, + strides=2, + padding='SAME', + data_format='channels_last', + dilation_rate=1, + name=None # 'maxpool1d' ): super().__init__(name) self.filter_size = self._filter_size = filter_size @@ -207,13 +207,13 @@ class MeanPool1d(Layer): """ def __init__( - self, - filter_size=3, - strides=2, - padding='SAME', - data_format='channels_last', - dilation_rate=1, - name=None # 'meanpool1d' + self, + filter_size=3, + strides=2, + padding='SAME', + data_format='channels_last', + dilation_rate=1, + name=None # 'meanpool1d' ): super().__init__(name) self.filter_size = self._filter_size = filter_size @@ -293,12 +293,12 @@ class MaxPool2d(Layer): """ def __init__( - self, - filter_size=(3, 3), - strides=(2, 2), - padding='SAME', - data_format='channels_last', - name=None # 'maxpool2d' + self, + filter_size=(3, 3), + strides=(2, 2), + padding='SAME', + data_format='channels_last', + name=None # 'maxpool2d' ): super().__init__(name) self.filter_size = filter_size @@ -366,12 +366,12 @@ class MeanPool2d(Layer): """ def __init__( - self, - filter_size=(3, 3), - strides=(2, 2), - padding='SAME', - data_format='channels_last', - name=None # 'meanpool2d' + self, + filter_size=(3, 3), + strides=(2, 2), + padding='SAME', + data_format='channels_last', + name=None # 'meanpool2d' ): super().__init__(name) self.filter_size = filter_size @@ -444,12 +444,12 @@ class MaxPool3d(Layer): """ def __init__( - self, - filter_size=(3, 3, 3), - strides=(2, 2, 2), - padding='VALID', - data_format='channels_last', - name=None # 'maxpool3d' + self, + filter_size=(3, 3, 3), + strides=(2, 2, 2), + padding='VALID', + data_format='channels_last', + name=None # 'maxpool3d' ): super().__init__(name) self.filter_size = filter_size @@ -525,12 +525,12 @@ class MeanPool3d(Layer): """ def __init__( - self, - filter_size=(3, 3, 3), - strides=(2, 2, 2), - padding='VALID', - data_format='channels_last', - name=None # 'meanpool3d' + self, + filter_size=(3, 3, 3), + strides=(2, 2, 2), + padding='VALID', + data_format='channels_last', + name=None # 'meanpool3d' ): super().__init__(name) self.filter_size = filter_size @@ -595,9 +595,9 @@ class GlobalMaxPool1d(Layer): """ def __init__( - self, - data_format="channels_last", - name=None # 'globalmaxpool1d' + self, + data_format="channels_last", + name=None # 'globalmaxpool1d' ): super().__init__(name) @@ -651,9 +651,9 @@ class GlobalMeanPool1d(Layer): """ def __init__( - self, - data_format='channels_last', - name=None # 'globalmeanpool1d' + self, + data_format='channels_last', + name=None # 'globalmeanpool1d' ): super().__init__(name) self.data_format = data_format @@ -706,9 +706,9 @@ class GlobalMaxPool2d(Layer): """ def __init__( - self, - data_format='channels_last', - name=None # 'globalmaxpool2d' + self, + data_format='channels_last', + name=None # 'globalmaxpool2d' ): super().__init__(name) self.data_format = data_format @@ -761,9 +761,9 @@ class GlobalMeanPool2d(Layer): """ def __init__( - self, - data_format='channels_last', - name=None # 'globalmeanpool2d' + self, + data_format='channels_last', + name=None # 'globalmeanpool2d' ): super().__init__(name) @@ -817,9 +817,9 @@ class GlobalMaxPool3d(Layer): """ def __init__( - self, - data_format='channels_last', - name=None # 'globalmaxpool3d' + self, + data_format='channels_last', + name=None # 'globalmaxpool3d' ): super().__init__(name) @@ -873,9 +873,9 @@ class GlobalMeanPool3d(Layer): """ def __init__( - self, - data_format='channels_last', - name=None # 'globalmeanpool3d' + self, + data_format='channels_last', + name=None # 'globalmeanpool3d' ): super().__init__(name) self.data_format = data_format @@ -929,9 +929,9 @@ class CornerPool2d(Layer): """ def __init__( - self, - mode='TopLeft', - name=None # 'cornerpool2d' + self, + mode='TopLeft', + name=None # 'cornerpool2d' ): super().__init__(name) self.mode = mode diff --git a/tensorlayer/layers/quantize.py b/tensorlayer/layers/quantize.py index 3b5b19635..fd19c9fa4 100644 --- a/tensorlayer/layers/quantize.py +++ b/tensorlayer/layers/quantize.py @@ -25,8 +25,8 @@ class Sign(Layer): # @deprecated_alias(layer='prev_layer', end_support_version=1.9) # TODO remove this line for the 1.9 release def __init__( - self, - name=None # 'sign', + self, + name=None # 'sign', ): super().__init__(name) logging.info("Sign %s" % self.name) diff --git a/tensorlayer/layers/recurrent.py b/tensorlayer/layers/recurrent.py index 56d476cd3..2d3558af4 100644 --- a/tensorlayer/layers/recurrent.py +++ b/tensorlayer/layers/recurrent.py @@ -8,7 +8,6 @@ from tensorlayer import logging from tensorlayer.decorators import deprecated_alias from tensorlayer.layers.core import Layer -import warnings # TODO: uncomment __all__ = [ @@ -139,13 +138,13 @@ class RNN(Layer): """ def __init__( - self, - cell, - return_last_output=False, - return_seq_2d=False, - return_last_state=True, - in_channels=None, - name=None, # 'rnn' + self, + cell, + return_last_output=False, + return_seq_2d=False, + return_last_state=True, + in_channels=None, + name=None, # 'rnn' ): super(RNN, self).__init__(name=name) @@ -389,14 +388,14 @@ class SimpleRNN(RNN): """ def __init__( - self, - units, - return_last_output=False, - return_seq_2d=False, - return_last_state=True, - in_channels=None, - name=None, # 'simplernn' - **kwargs + self, + units, + return_last_output=False, + return_seq_2d=False, + return_last_state=True, + in_channels=None, + name=None, # 'simplernn' + **kwargs ): super(SimpleRNN, self).__init__( cell=tf.keras.layers.SimpleRNNCell(units=units, **kwargs), return_last_output=return_last_output, @@ -467,14 +466,14 @@ class GRURNN(RNN): """ def __init__( - self, - units, - return_last_output=False, - return_seq_2d=False, - return_last_state=True, - in_channels=None, - name=None, # 'grurnn' - **kwargs + self, + units, + return_last_output=False, + return_seq_2d=False, + return_last_state=True, + in_channels=None, + name=None, # 'grurnn' + **kwargs ): super(GRURNN, self).__init__( cell=tf.keras.layers.GRUCell(units=units, **kwargs), return_last_output=return_last_output, @@ -545,14 +544,14 @@ class LSTMRNN(RNN): """ def __init__( - self, - units, - return_last_output=False, - return_seq_2d=False, - return_last_state=True, - in_channels=None, - name=None, # 'lstmrnn' - **kwargs + self, + units, + return_last_output=False, + return_seq_2d=False, + return_last_state=True, + in_channels=None, + name=None, # 'lstmrnn' + **kwargs ): super(LSTMRNN, self).__init__( cell=tf.keras.layers.LSTMCell(units=units, **kwargs), return_last_output=return_last_output, @@ -633,13 +632,13 @@ class BiRNN(Layer): """ def __init__( - self, - fw_cell, - bw_cell, - return_seq_2d=False, - return_last_state=False, - in_channels=None, - name=None, # 'birnn' + self, + fw_cell, + bw_cell, + return_seq_2d=False, + return_last_state=False, + in_channels=None, + name=None, # 'birnn' ): super(BiRNN, self).__init__(name) diff --git a/tensorlayer/layers/scale.py b/tensorlayer/layers/scale.py index 9054f50e8..3e14e462a 100644 --- a/tensorlayer/layers/scale.py +++ b/tensorlayer/layers/scale.py @@ -33,9 +33,9 @@ class Scale(Layer): """ def __init__( - self, - init_scale=0.05, - name='scale', + self, + init_scale=0.05, + name='scale', ): super(Scale, self).__init__(name) self.init_scale = init_scale diff --git a/tensorlayer/layers/spatial_transformer.py b/tensorlayer/layers/spatial_transformer.py index df8edcb2a..74822d565 100644 --- a/tensorlayer/layers/spatial_transformer.py +++ b/tensorlayer/layers/spatial_transformer.py @@ -230,11 +230,11 @@ class SpatialTransformer2dAffine(Layer): """ def __init__( - self, - out_size=(40, 40), - in_channels=None, - data_format='channel_last', - name=None, + self, + out_size=(40, 40), + in_channels=None, + data_format='channel_last', + name=None, ): super(SpatialTransformer2dAffine, self).__init__(name) diff --git a/tensorlayer/layers/stack.py b/tensorlayer/layers/stack.py index c31327989..4e37d1f9a 100644 --- a/tensorlayer/layers/stack.py +++ b/tensorlayer/layers/stack.py @@ -38,9 +38,9 @@ class Stack(Layer): """ def __init__( - self, - axis=1, - name=None, #'stack', + self, + axis=1, + name=None, #'stack', ): super().__init__(name) self.axis = axis diff --git a/tensorlayer/logging/contrib/hyperdash.py b/tensorlayer/logging/contrib/hyperdash.py index 6e19c8e9b..7c21e65ea 100644 --- a/tensorlayer/logging/contrib/hyperdash.py +++ b/tensorlayer/logging/contrib/hyperdash.py @@ -46,10 +46,10 @@ def monitor(cls, model_name, api_key=None, capture_io=True): class Experiment(hd.Experiment): def __init__( - self, - model_name, - api_key=None, - capture_io=True, + self, + model_name, + api_key=None, + capture_io=True, ): if api_key is not None: diff --git a/tensorlayer/models/__init__.py b/tensorlayer/models/__init__.py index 19f5bb665..7e54c8a4b 100644 --- a/tensorlayer/models/__init__.py +++ b/tensorlayer/models/__init__.py @@ -4,9 +4,9 @@ # """A collections of pre-defined well known models.""" from .core import * -from .resnet import ResNet50 from .mobilenetv1 import MobileNetV1 -from .squeezenetv1 import SqueezeNetV1 -from .vgg import * +from .resnet import ResNet50 from .seq2seq import Seq2seq from .seq2seq_with_attention import Seq2seqLuongAttention +from .squeezenetv1 import SqueezeNetV1 +from .vgg import * diff --git a/tensorlayer/models/resnet.py b/tensorlayer/models/resnet.py index 7df069468..458f25912 100644 --- a/tensorlayer/models/resnet.py +++ b/tensorlayer/models/resnet.py @@ -11,9 +11,10 @@ import os import tensorflow as tf + from tensorlayer import logging from tensorlayer.files import (assign_weights, load_npz, maybe_download_and_extract) -from tensorlayer.layers import (BatchNorm, Conv2d, Elementwise, GlobalMeanPool2d, MaxPool2d, Input, Dense) +from tensorlayer.layers import (BatchNorm, Conv2d, Dense, Elementwise, GlobalMeanPool2d, Input, MaxPool2d) from tensorlayer.models import Model __all__ = [ diff --git a/tensorlayer/models/seq2seq_with_attention.py b/tensorlayer/models/seq2seq_with_attention.py index d601e33c8..800bbaa61 100644 --- a/tensorlayer/models/seq2seq_with_attention.py +++ b/tensorlayer/models/seq2seq_with_attention.py @@ -3,6 +3,7 @@ import numpy as np import tensorflow as tf + import tensorlayer as tl from tensorlayer.layers import Dense, Dropout, Input from tensorlayer.layers.core import Layer diff --git a/tensorlayer/nlp.py b/tensorlayer/nlp.py index f02f203a8..1f22584bc 100755 --- a/tensorlayer/nlp.py +++ b/tensorlayer/nlp.py @@ -906,8 +906,8 @@ def basic_tokenizer(sentence, _WORD_SPLIT=re.compile(b"([.,!?\"':;)(])")): def create_vocabulary( - vocabulary_path, data_path, max_vocabulary_size, tokenizer=None, normalize_digits=True, - _DIGIT_RE=re.compile(br"\d"), _START_VOCAB=None + vocabulary_path, data_path, max_vocabulary_size, tokenizer=None, normalize_digits=True, + _DIGIT_RE=re.compile(br"\d"), _START_VOCAB=None ): r"""Create vocabulary file (if it does not exist yet) from data file. @@ -1014,7 +1014,7 @@ def initialize_vocabulary(vocabulary_path): def sentence_to_token_ids( - sentence, vocabulary, tokenizer=None, normalize_digits=True, UNK_ID=3, _DIGIT_RE=re.compile(br"\d") + sentence, vocabulary, tokenizer=None, normalize_digits=True, UNK_ID=3, _DIGIT_RE=re.compile(br"\d") ): """Convert a string to list of integers representing token-ids. @@ -1050,8 +1050,8 @@ def sentence_to_token_ids( def data_to_token_ids( - data_path, target_path, vocabulary_path, tokenizer=None, normalize_digits=True, UNK_ID=3, - _DIGIT_RE=re.compile(br"\d") + data_path, target_path, vocabulary_path, tokenizer=None, normalize_digits=True, UNK_ID=3, + _DIGIT_RE=re.compile(br"\d") ): """Tokenize data file and turn into token-ids using given vocabulary file. diff --git a/tensorlayer/prepro.py b/tensorlayer/prepro.py index d2c31e600..3ba2f308c 100644 --- a/tensorlayer/prepro.py +++ b/tensorlayer/prepro.py @@ -622,8 +622,7 @@ def affine_transform_keypoints(coords_list, transform_matrix): def projective_transform_by_points( - x, src, dst, map_args=None, output_shape=None, order=1, mode='constant', cval=0.0, clip=True, - preserve_range=False + x, src, dst, map_args=None, output_shape=None, order=1, mode='constant', cval=0.0, clip=True, preserve_range=False ): """Projective transform by given coordinates, usually 4 coordinates. @@ -700,7 +699,7 @@ def projective_transform_by_points( # rotate def rotation( - x, rg=20, is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0., order=1 + x, rg=20, is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0., order=1 ): """Rotate an image randomly or non-randomly. @@ -746,7 +745,7 @@ def rotation( def rotation_multi( - x, rg=20, is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0., order=1 + x, rg=20, is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0., order=1 ): """Rotate multiple images with the same arguments, randomly or non-randomly. Usually be used for image segmentation which x=[X, Y], X and Y should be matched. @@ -956,8 +955,8 @@ def flip_axis_multi(x, axis, is_random=False): # shift def shift( - x, wrg=0.1, hrg=0.1, is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0., - order=1 + x, wrg=0.1, hrg=0.1, is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0., + order=1 ): """Shift an image randomly or non-randomly. @@ -1000,8 +999,8 @@ def shift( def shift_multi( - x, wrg=0.1, hrg=0.1, is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0., - order=1 + x, wrg=0.1, hrg=0.1, is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0., + order=1 ): """Shift images with the same arguments, randomly or non-randomly. Usually be used for image segmentation which x=[X, Y], X and Y should be matched. @@ -1036,8 +1035,7 @@ def shift_multi( # shear def shear( - x, intensity=0.1, is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0., - order=1 + x, intensity=0.1, is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0., order=1 ): """Shear an image randomly or non-randomly. @@ -1082,8 +1080,7 @@ def shear( def shear_multi( - x, intensity=0.1, is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0., - order=1 + x, intensity=0.1, is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0., order=1 ): """Shear images with the same arguments, randomly or non-randomly. Usually be used for image segmentation which x=[X, Y], X and Y should be matched. @@ -1116,8 +1113,8 @@ def shear_multi( def shear2( - x, shear=(0.1, 0.1), is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0., - order=1 + x, shear=(0.1, 0.1), is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0., + order=1 ): """Shear an image randomly or non-randomly. @@ -1169,8 +1166,8 @@ def shear2( def shear_multi2( - x, shear=(0.1, 0.1), is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0., - order=1 + x, shear=(0.1, 0.1), is_random=False, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', cval=0., + order=1 ): """Shear images with the same arguments, randomly or non-randomly. Usually be used for image segmentation which x=[X, Y], X and Y should be matched. @@ -1210,8 +1207,8 @@ def shear_multi2( # swirl def swirl( - x, center=None, strength=1, radius=100, rotation=0, output_shape=None, order=1, mode='constant', cval=0, - clip=True, preserve_range=False, is_random=False + x, center=None, strength=1, radius=100, rotation=0, output_shape=None, order=1, mode='constant', cval=0, clip=True, + preserve_range=False, is_random=False ): """Swirl an image randomly or non-randomly, see `scikit-image swirl API `__ and `example `__. @@ -1284,8 +1281,8 @@ def swirl( def swirl_multi( - x, center=None, strength=1, radius=100, rotation=0, output_shape=None, order=1, mode='constant', cval=0, - clip=True, preserve_range=False, is_random=False + x, center=None, strength=1, radius=100, rotation=0, output_shape=None, order=1, mode='constant', cval=0, clip=True, + preserve_range=False, is_random=False ): """Swirl multiple images with the same arguments, randomly or non-randomly. Usually be used for image segmentation which x=[X, Y], X and Y should be matched. @@ -1902,7 +1899,7 @@ def pixel_value_scale(im, val=0.9, clip=None, is_random=False): # normailization def samplewise_norm( - x, rescale=None, samplewise_center=False, samplewise_std_normalization=False, channel_index=2, epsilon=1e-7 + x, rescale=None, samplewise_center=False, samplewise_std_normalization=False, channel_index=2, epsilon=1e-7 ): """Normalize an image by rescale, samplewise centering and samplewise centering in order. @@ -2850,8 +2847,8 @@ def obj_box_imresize(im, coords=None, size=None, interp='bicubic', mode=None, is def obj_box_crop( - im, classes=None, coords=None, wrg=100, hrg=100, is_rescale=False, is_center=False, is_random=False, - thresh_wh=0.02, thresh_wh2=12. + im, classes=None, coords=None, wrg=100, hrg=100, is_rescale=False, is_center=False, is_random=False, thresh_wh=0.02, + thresh_wh2=12. ): """Randomly or centrally crop an image, and compute the new bounding box coordinates. Objects outside the cropped image will be removed. @@ -3003,8 +3000,8 @@ def _get_coord(coord): def obj_box_shift( - im, classes=None, coords=None, wrg=0.1, hrg=0.1, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', - cval=0., order=1, is_rescale=False, is_center=False, is_random=False, thresh_wh=0.02, thresh_wh2=12. + im, classes=None, coords=None, wrg=0.1, hrg=0.1, row_index=0, col_index=1, channel_index=2, fill_mode='nearest', + cval=0., order=1, is_rescale=False, is_center=False, is_random=False, thresh_wh=0.02, thresh_wh2=12. ): """Shift an image randomly or non-randomly, and compute the new bounding box coordinates. Objects outside the cropped image will be removed. @@ -3138,9 +3135,9 @@ def _get_coord(coord): def obj_box_zoom( - im, classes=None, coords=None, zoom_range=(0.9, 1.1), row_index=0, col_index=1, channel_index=2, - fill_mode='nearest', cval=0., order=1, is_rescale=False, is_center=False, is_random=False, thresh_wh=0.02, - thresh_wh2=12. + im, classes=None, coords=None, zoom_range=(0.9, 1.1), row_index=0, col_index=1, channel_index=2, + fill_mode='nearest', cval=0., order=1, is_rescale=False, is_center=False, is_random=False, thresh_wh=0.02, + thresh_wh2=12. ): """Zoom in and out of a single image, randomly or non-randomly, and compute the new bounding box coordinates. Objects outside the cropped image will be removed. @@ -3921,7 +3918,7 @@ def _largest_rotated_rect(w, h, angle): def keypoint_random_flip( - image, annos, mask=None, prob=0.5, flip_list=(0, 1, 5, 6, 7, 2, 3, 4, 11, 12, 13, 8, 9, 10, 15, 14, 17, 16, 18) + image, annos, mask=None, prob=0.5, flip_list=(0, 1, 5, 6, 7, 2, 3, 4, 11, 12, 13, 8, 9, 10, 15, 14, 17, 16, 18) ): """Flip an image and corresponding keypoints. @@ -4024,8 +4021,7 @@ def keypoint_random_resize(image, annos, mask=None, zoom_range=(0.8, 1.2)): def keypoint_random_resize_shortestedge( - image, annos, mask=None, min_size=(368, 368), zoom_range=(0.8, 1.2), - pad_val=(0, 0, np.random.uniform(0.0, 1.0)) + image, annos, mask=None, min_size=(368, 368), zoom_range=(0.8, 1.2), pad_val=(0, 0, np.random.uniform(0.0, 1.0)) ): """Randomly resize an image and corresponding keypoints based on shorter edgeself. If the resized image is smaller than `min_size`, uses padding to make shape matchs `min_size`. diff --git a/tensorlayer/utils.py b/tensorlayer/utils.py index d6b8e6d78..508beb7bb 100644 --- a/tensorlayer/utils.py +++ b/tensorlayer/utils.py @@ -24,9 +24,9 @@ def fit( - network, train_op, cost, X_train, y_train, acc=None, batch_size=100, n_epoch=100, print_freq=5, X_val=None, - y_val=None, eval_train=True, tensorboard_dir=None, tensorboard_epoch_freq=5, tensorboard_weight_histograms=True, - tensorboard_graph_vis=True + network, train_op, cost, X_train, y_train, acc=None, batch_size=100, n_epoch=100, print_freq=5, X_val=None, + y_val=None, eval_train=True, tensorboard_dir=None, tensorboard_epoch_freq=5, tensorboard_weight_histograms=True, + tensorboard_graph_vis=True ): """Training a given non time-series network by the given cost function, training data, batch_size, n_epoch etc. @@ -560,7 +560,7 @@ def set_gpu_fraction(gpu_fraction=0.3): def train_epoch( - network, X, y, cost, train_op=tf.optimizers.Adam(learning_rate=0.0001), acc=None, batch_size=100, shuffle=True + network, X, y, cost, train_op=tf.optimizers.Adam(learning_rate=0.0001), acc=None, batch_size=100, shuffle=True ): """Training a given non time-series network by the given cost function, training data, batch_size etc. for one epoch. diff --git a/tensorlayer/visualize.py b/tensorlayer/visualize.py index 35b428390..72c1b184c 100644 --- a/tensorlayer/visualize.py +++ b/tensorlayer/visualize.py @@ -146,7 +146,7 @@ def imsave(images, size, path): def draw_boxes_and_labels_to_image( - image, classes, coords, scores, classes_list, is_center=True, is_rescale=True, save_name=None + image, classes, coords, scores, classes_list, is_center=True, is_rescale=True, save_name=None ): """Draw bboxes and class labels on image. Return or save the image with bboxes, example in the docs of ``tl.prepro``. diff --git a/tests/files/test_utils_saveload.py b/tests/files/test_utils_saveload.py index 58a1d374a..ea51b0ff4 100644 --- a/tests/files/test_utils_saveload.py +++ b/tests/files/test_utils_saveload.py @@ -4,16 +4,16 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import numpy as np import tensorflow as tf + import tensorlayer as tl from tensorlayer.layers import * from tensorlayer.models import * - from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + def basic_static_model(): ni = Input((None, 24, 24, 3)) diff --git a/tests/layers/test_layernode.py b/tests/layers/test_layernode.py index d592f54f3..957857f9a 100644 --- a/tests/layers/test_layernode.py +++ b/tests/layers/test_layernode.py @@ -3,17 +3,17 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - +import numpy as np import tensorflow as tf +from tensorflow.python.ops.rnn_cell import LSTMCell + import tensorlayer as tl from tensorlayer.layers import * from tensorlayer.models import Model -from tensorflow.python.ops.rnn_cell import LSTMCell -import numpy as np - from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class LayerNode_Test(CustomTestCase): diff --git a/tests/layers/test_layers_activation.py b/tests/layers/test_layers_activation.py index 69bd0282f..e2f850f1e 100644 --- a/tests/layers/test_layers_activation.py +++ b/tests/layers/test_layers_activation.py @@ -4,14 +4,14 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import numpy as np import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Activation_Layer_Test(CustomTestCase): diff --git a/tests/layers/test_layers_convolution.py b/tests/layers/test_layers_convolution.py index b768600de..059d1b118 100644 --- a/tests/layers/test_layers_convolution.py +++ b/tests/layers/test_layers_convolution.py @@ -4,15 +4,15 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf + import tensorlayer as tl from tensorlayer.layers import * from tensorlayer.models import * - from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Convolution_1D_Test(CustomTestCase): diff --git a/tests/layers/test_layers_core_act.py b/tests/layers/test_layers_core_act.py index 0da41fea0..549a192ab 100644 --- a/tests/layers/test_layers_core_act.py +++ b/tests/layers/test_layers_core_act.py @@ -3,15 +3,15 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf + import tensorlayer as tl from tensorlayer.layers import * from tensorlayer.models import * - from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Convolution_2D_Test(CustomTestCase): diff --git a/tests/layers/test_layers_core_basedense_dropout.py b/tests/layers/test_layers_core_basedense_dropout.py index 19178f5d6..c3ecfebc5 100644 --- a/tests/layers/test_layers_core_basedense_dropout.py +++ b/tests/layers/test_layers_core_basedense_dropout.py @@ -4,16 +4,16 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import numpy as np import tensorflow as tf + import tensorlayer as tl from tensorlayer.layers import * from tensorlayer.models import * - from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Core_Test(CustomTestCase): diff --git a/tests/layers/test_layers_core_nested.py b/tests/layers/test_layers_core_nested.py index e44c12f3a..1c5ef5908 100644 --- a/tests/layers/test_layers_core_nested.py +++ b/tests/layers/test_layers_core_nested.py @@ -3,14 +3,14 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - -import tensorflow as tf -import tensorlayer as tl import numpy as np +import tensorflow as tf +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_nested(CustomTestCase): diff --git a/tests/layers/test_layers_deformable_convolution.py b/tests/layers/test_layers_deformable_convolution.py index b31d5ce98..8c5df8e8d 100644 --- a/tests/layers/test_layers_deformable_convolution.py +++ b/tests/layers/test_layers_deformable_convolution.py @@ -4,15 +4,15 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf + import tensorlayer as tl from tensorlayer.layers import * from tensorlayer.models import * - from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Convolution_2D_Test(CustomTestCase): diff --git a/tests/layers/test_layers_dense.py b/tests/layers/test_layers_dense.py index 61cfd68b8..6486cfbc1 100644 --- a/tests/layers/test_layers_dense.py +++ b/tests/layers/test_layers_dense.py @@ -3,15 +3,15 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - +import numpy as np import tensorflow as tf + import tensorlayer as tl from tensorlayer.layers import * from tensorlayer.models import * - from tests.utils import CustomTestCase -import numpy as np + +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' class Layer_BinaryDense_Test(CustomTestCase): diff --git a/tests/layers/test_layers_embedding.py b/tests/layers/test_layers_embedding.py index bfd05ada9..4377b79a7 100644 --- a/tests/layers/test_layers_embedding.py +++ b/tests/layers/test_layers_embedding.py @@ -4,14 +4,14 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - -import tensorflow as tf -import tensorlayer as tl import numpy as np +import tensorflow as tf +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Embed_Test(CustomTestCase): diff --git a/tests/layers/test_layers_extend.py b/tests/layers/test_layers_extend.py index 6e1f32654..5d4decc60 100644 --- a/tests/layers/test_layers_extend.py +++ b/tests/layers/test_layers_extend.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Extend_Test(CustomTestCase): diff --git a/tests/layers/test_layers_lambda.py b/tests/layers/test_layers_lambda.py index 0f2fd22f3..cb487e86f 100644 --- a/tests/layers/test_layers_lambda.py +++ b/tests/layers/test_layers_lambda.py @@ -3,15 +3,15 @@ import os import unittest -import numpy as np - -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' +import numpy as np import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Lambda_Test(CustomTestCase): diff --git a/tests/layers/test_layers_merge.py b/tests/layers/test_layers_merge.py index 054cf036c..75e711054 100644 --- a/tests/layers/test_layers_merge.py +++ b/tests/layers/test_layers_merge.py @@ -4,14 +4,14 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import numpy as np import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Merge_Test(CustomTestCase): diff --git a/tests/layers/test_layers_noise.py b/tests/layers/test_layers_noise.py index 8e12a4d50..056410ba1 100644 --- a/tests/layers/test_layers_noise.py +++ b/tests/layers/test_layers_noise.py @@ -4,14 +4,14 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf + import tensorlayer as tl from tensorlayer.layers import * - from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Convolution_1D_Test(CustomTestCase): diff --git a/tests/layers/test_layers_normalization.py b/tests/layers/test_layers_normalization.py index c223f61ed..b6bb30ad2 100644 --- a/tests/layers/test_layers_normalization.py +++ b/tests/layers/test_layers_normalization.py @@ -4,14 +4,15 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf + import tensorlayer as tl from tensorlayer.layers import * from tensorlayer.models import Model from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Laye_BatchNorm_Test(CustomTestCase): diff --git a/tests/layers/test_layers_padding.py b/tests/layers/test_layers_padding.py index 9f9db83a9..a92da5197 100644 --- a/tests/layers/test_layers_padding.py +++ b/tests/layers/test_layers_padding.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Padding_Test(CustomTestCase): diff --git a/tests/layers/test_layers_pooling.py b/tests/layers/test_layers_pooling.py index 5a2d1c311..5ab3e3e98 100644 --- a/tests/layers/test_layers_pooling.py +++ b/tests/layers/test_layers_pooling.py @@ -4,14 +4,14 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf + import tensorlayer as tl from tensorlayer.layers import * - from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Pooling_Test(CustomTestCase): diff --git a/tests/layers/test_layers_recurrent.py b/tests/layers/test_layers_recurrent.py index 4309eae02..6f9eff3ea 100644 --- a/tests/layers/test_layers_recurrent.py +++ b/tests/layers/test_layers_recurrent.py @@ -4,14 +4,14 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import numpy as np import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_RNN_Test(CustomTestCase): diff --git a/tests/layers/test_layers_resampling.py b/tests/layers/test_layers_resampling.py index f683cf537..643303558 100644 --- a/tests/layers/test_layers_resampling.py +++ b/tests/layers/test_layers_resampling.py @@ -1,19 +1,19 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import sys -sys.path.append("/home/wurundi/workspace/tensorlayer2") - import os +import sys import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf + import tensorlayer as tl from tensorlayer.layers import * - from tests.utils import CustomTestCase +sys.path.append("/home/wurundi/workspace/tensorlayer2") + +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Pooling_Test(CustomTestCase): diff --git a/tests/layers/test_layers_scale.py b/tests/layers/test_layers_scale.py index 5393c42e7..fdf5228ed 100644 --- a/tests/layers/test_layers_scale.py +++ b/tests/layers/test_layers_scale.py @@ -3,15 +3,15 @@ import os import unittest -import numpy as np - -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' +import numpy as np import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Scale_Test(CustomTestCase): diff --git a/tests/layers/test_layers_shape.py b/tests/layers/test_layers_shape.py index 48b4d378f..2ece6b0b7 100644 --- a/tests/layers/test_layers_shape.py +++ b/tests/layers/test_layers_shape.py @@ -3,15 +3,15 @@ import os import unittest -import numpy as np - -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' +import numpy as np import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Shape_Test(CustomTestCase): diff --git a/tests/layers/test_layers_stack.py b/tests/layers/test_layers_stack.py index 046005590..4005c61e8 100644 --- a/tests/layers/test_layers_stack.py +++ b/tests/layers/test_layers_stack.py @@ -3,15 +3,15 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf + import tensorlayer as tl from tensorlayer.layers import * from tensorlayer.models import * - from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Stack_Test(CustomTestCase): diff --git a/tests/models/test_auto_naming.py b/tests/models/test_auto_naming.py index fb8f03720..65337a8c9 100644 --- a/tests/models/test_auto_naming.py +++ b/tests/models/test_auto_naming.py @@ -3,16 +3,16 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import numpy as np import tensorflow as tf + import tensorlayer as tl from tensorlayer.layers import * from tensorlayer.models import * - from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + def basic_static_model(name=None, conv1_name="conv1", conv2_name="conv2"): ni = Input((None, 24, 24, 3)) diff --git a/tests/models/test_keras_save.py b/tests/models/test_keras_save.py index 2d40b31ef..caadd6574 100644 --- a/tests/models/test_keras_save.py +++ b/tests/models/test_keras_save.py @@ -1,8 +1,8 @@ -from tensorflow.python.keras.applications import VGG16 -from tensorflow.python.keras.layers import Dense, Conv2D +import tensorflow as tf from tensorflow.python.keras import Model +from tensorflow.python.keras.applications import VGG16 +from tensorflow.python.keras.layers import Conv2D, Dense from tensorflow.python.training import saver -import tensorflow as tf # get the whole model # vgg = VGG16(weights=None) diff --git a/tests/models/test_model_core.py b/tests/models/test_model_core.py index 3db470f9d..0a98e154d 100644 --- a/tests/models/test_model_core.py +++ b/tests/models/test_model_core.py @@ -3,16 +3,16 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import numpy as np import tensorflow as tf + import tensorlayer as tl from tensorlayer.layers import * from tensorlayer.models import * - from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + def basic_static_model(): ni = Input((None, 24, 24, 3)) diff --git a/tests/models/test_model_save.py b/tests/models/test_model_save.py index ba224ee25..001e9a3df 100644 --- a/tests/models/test_model_save.py +++ b/tests/models/test_model_save.py @@ -3,16 +3,16 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import numpy as np import tensorflow as tf + import tensorlayer as tl from tensorlayer.layers import * from tensorlayer.models import * - from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + def basic_static_model(include_top=True): ni = Input((None, 24, 24, 3)) @@ -80,7 +80,6 @@ def setUpClass(cls): print([l.name for l in cls.dynamic_basic.all_layers]) print([l.name for l in cls.dynamic_basic_skip.all_layers]) - pass @classmethod def tearDownClass(cls): diff --git a/tests/models/test_model_save_graph.py b/tests/models/test_model_save_graph.py index 3e527159d..1e9b898a1 100644 --- a/tests/models/test_model_save_graph.py +++ b/tests/models/test_model_save_graph.py @@ -4,16 +4,16 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import numpy as np import tensorflow as tf + import tensorlayer as tl from tensorlayer.layers import * from tensorlayer.models import * - from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + def RemoveDateInConfig(config): config["version_info"]["save_date"] = None diff --git a/tests/models/test_seq2seq_model.py b/tests/models/test_seq2seq_model.py index d77aa47ba..f32db9193 100644 --- a/tests/models/test_seq2seq_model.py +++ b/tests/models/test_seq2seq_model.py @@ -4,16 +4,17 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import numpy as np import tensorflow as tf -import tensorlayer as tl -from tqdm import tqdm from sklearn.utils import shuffle + +import tensorlayer as tl +from tensorlayer.cost import cross_entropy_seq from tensorlayer.models.seq2seq import Seq2seq from tests.utils import CustomTestCase -from tensorlayer.cost import cross_entropy_seq +from tqdm import tqdm + +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' class Model_SEQ2SEQ_Test(CustomTestCase): diff --git a/tests/models/test_seq2seq_with_attention.py b/tests/models/test_seq2seq_with_attention.py index d7dbeae34..b9ee17c94 100644 --- a/tests/models/test_seq2seq_with_attention.py +++ b/tests/models/test_seq2seq_with_attention.py @@ -4,16 +4,17 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import numpy as np import tensorflow as tf -import tensorlayer as tl -from tqdm import tqdm from sklearn.utils import shuffle + +import tensorlayer as tl +from tensorlayer.cost import cross_entropy_seq from tensorlayer.models.seq2seq_with_attention import Seq2seqLuongAttention from tests.utils import CustomTestCase -from tensorlayer.cost import cross_entropy_seq +from tqdm import tqdm + +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' class Model_SEQ2SEQ_WITH_ATTENTION_Test(CustomTestCase): diff --git a/tests/pending/test_array_ops.py b/tests/pending/test_array_ops.py index 56b80d485..7813e286e 100644 --- a/tests/pending/test_array_ops.py +++ b/tests/pending/test_array_ops.py @@ -4,15 +4,14 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - -import tensorflow as tf -import tensorlayer as tl - import numpy as np +import tensorflow as tf +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Array_Op_Alphas_Test(CustomTestCase): diff --git a/tests/pending/test_decorators.py b/tests/pending/test_decorators.py index cc8878543..fbe91b2ba 100644 --- a/tests/pending/test_decorators.py +++ b/tests/pending/test_decorators.py @@ -4,15 +4,14 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tensorlayer.decorators import private_method - from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Pooling_Test(CustomTestCase): diff --git a/tests/pending/test_documentation.py b/tests/pending/test_documentation.py index 211142e8d..332a5cb03 100755 --- a/tests/pending/test_documentation.py +++ b/tests/pending/test_documentation.py @@ -4,10 +4,10 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - from sphinx.application import Sphinx +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class DocTest(unittest.TestCase): source_dir = u'docs/' diff --git a/tests/pending/test_layers_basic.py b/tests/pending/test_layers_basic.py index 2771f961a..209663bd2 100644 --- a/tests/pending/test_layers_basic.py +++ b/tests/pending/test_layers_basic.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Basic_Test(CustomTestCase): diff --git a/tests/pending/test_layers_flow_control.py b/tests/pending/test_layers_flow_control.py index d86eb217a..b82c460b6 100644 --- a/tests/pending/test_layers_flow_control.py +++ b/tests/pending/test_layers_flow_control.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Flow_Control_Test(CustomTestCase): diff --git a/tests/pending/test_layers_importer.py b/tests/pending/test_layers_importer.py index 1c1321acb..c5a2f0d3c 100644 --- a/tests/pending/test_layers_importer.py +++ b/tests/pending/test_layers_importer.py @@ -4,20 +4,17 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf +from tensorflow.contrib.slim.python.slim.nets.inception_v3 import (inception_v3, inception_v3_arg_scope) + +import tensorlayer as tl +from tests.utils import CustomTestCase -from tensorflow.contrib.slim.python.slim.nets.inception_v3 import inception_v3 -from tensorflow.contrib.slim.python.slim.nets.inception_v3 import inception_v3_arg_scope +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' slim = tf.contrib.slim keras = tf.keras -import tensorlayer as tl - -from tests.utils import CustomTestCase - class Layer_Importer_Test(CustomTestCase): diff --git a/tests/pending/test_layers_normalization.py b/tests/pending/test_layers_normalization.py index d0891abf1..e6fd8bd81 100644 --- a/tests/pending/test_layers_normalization.py +++ b/tests/pending/test_layers_normalization.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + def model(x, is_train=True, reuse=False): with tf.variable_scope("model", reuse=reuse): diff --git a/tests/pending/test_layers_padding.py b/tests/pending/test_layers_padding.py index ab6f6b54d..163838cb5 100644 --- a/tests/pending/test_layers_padding.py +++ b/tests/pending/test_layers_padding.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Padding_Test(CustomTestCase): diff --git a/tests/pending/test_layers_spatial_transformer.py b/tests/pending/test_layers_spatial_transformer.py index 61a9a23ed..b585f6032 100644 --- a/tests/pending/test_layers_spatial_transformer.py +++ b/tests/pending/test_layers_spatial_transformer.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + def model(x, is_train, reuse): with tf.variable_scope("STN", reuse=reuse): diff --git a/tests/pending/test_layers_stack.py b/tests/pending/test_layers_stack.py index 0745a834d..c223b0553 100644 --- a/tests/pending/test_layers_stack.py +++ b/tests/pending/test_layers_stack.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Stack_Test(CustomTestCase): diff --git a/tests/pending/test_layers_super_resolution.py b/tests/pending/test_layers_super_resolution.py index 9b359cb99..f60986700 100644 --- a/tests/pending/test_layers_super_resolution.py +++ b/tests/pending/test_layers_super_resolution.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Super_Resolution_Test(CustomTestCase): diff --git a/tests/pending/test_layers_time_distributed.py b/tests/pending/test_layers_time_distributed.py index a97c51117..bb2f33fc0 100644 --- a/tests/pending/test_layers_time_distributed.py +++ b/tests/pending/test_layers_time_distributed.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + def model(x, is_train=True, reuse=False, name_scope="env1"): with tf.variable_scope(name_scope, reuse=reuse): diff --git a/tests/pending/test_logging.py b/tests/pending/test_logging.py index fffdf7cc5..59f171b21 100644 --- a/tests/pending/test_logging.py +++ b/tests/pending/test_logging.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class TL_Logger_Test(CustomTestCase): diff --git a/tests/pending/test_logging_hyperdash.py b/tests/pending/test_logging_hyperdash.py index c39e66160..6616bd1c9 100644 --- a/tests/pending/test_logging_hyperdash.py +++ b/tests/pending/test_logging_hyperdash.py @@ -2,19 +2,17 @@ # -*- coding: utf-8 -*- import os -import unittest - import time - -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' +import unittest import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tensorlayer.logging.contrib import hyperdash as hd - from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class TL_Logger_Test(CustomTestCase): diff --git a/tests/pending/test_mnist_simple.py b/tests/pending/test_mnist_simple.py index 5fe68c97b..90fa18b36 100644 --- a/tests/pending/test_mnist_simple.py +++ b/tests/pending/test_mnist_simple.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Simple_MNIST_Test(CustomTestCase): diff --git a/tests/pending/test_models.py b/tests/pending/test_models.py index 4378ea6a0..dd0e07cbd 100644 --- a/tests/pending/test_models.py +++ b/tests/pending/test_models.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class VGG_Model_Test(CustomTestCase): diff --git a/tests/pending/test_optimizer_amsgrad.py b/tests/pending/test_optimizer_amsgrad.py index 0ceb8b372..919881c41 100644 --- a/tests/pending/test_optimizer_amsgrad.py +++ b/tests/pending/test_optimizer_amsgrad.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Pooling_Test(CustomTestCase): diff --git a/tests/pending/test_pydocstyle.py b/tests/pending/test_pydocstyle.py index b93bf74db..5a7143d1d 100755 --- a/tests/pending/test_pydocstyle.py +++ b/tests/pending/test_pydocstyle.py @@ -4,12 +4,10 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - +from pydocstyle.checker import check, violations from tests.utils import list_all_py_files -from pydocstyle.checker import check -from pydocstyle.checker import violations +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' registry = violations.ErrorRegistry diff --git a/tests/pending/test_reuse_mlp.py b/tests/pending/test_reuse_mlp.py index 3ca435b38..5992b8bda 100644 --- a/tests/pending/test_reuse_mlp.py +++ b/tests/pending/test_reuse_mlp.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + # define the network def mlp(x, is_train=True, reuse=False): diff --git a/tests/pending/test_tf_layers.py b/tests/pending/test_tf_layers.py index dc04a06ff..3ba11820c 100644 --- a/tests/pending/test_tf_layers.py +++ b/tests/pending/test_tf_layers.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Layer_Convolution_1D_Test(CustomTestCase): diff --git a/tests/pending/test_timeout.py b/tests/pending/test_timeout.py index 9b5dda621..914c0bdf6 100644 --- a/tests/pending/test_timeout.py +++ b/tests/pending/test_timeout.py @@ -3,22 +3,16 @@ import os import time - import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl - -from tests.utils import WindowsError -from tests.utils import TimeoutError - -from tests.utils import TimeoutContext -from tests.utils import CustomTestCase +import tensorlayer as tl +from tests.utils import (CustomTestCase, TimeoutContext, TimeoutError, WindowsError) from tests.utils.custom_networks import InceptionV4_Network +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + if os.getenv("TRAVIS", None) is not None: NETWORK_CREATION_TIMEOUT = 120 # Seconds before timeout else: diff --git a/tests/pending/test_utils_predict.py b/tests/pending/test_utils_predict.py index ec751e275..bea7eb99e 100644 --- a/tests/pending/test_utils_predict.py +++ b/tests/pending/test_utils_predict.py @@ -4,15 +4,14 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import numpy as np - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Util_Predict_Test(CustomTestCase): diff --git a/tests/pending/test_yapf_format.py b/tests/pending/test_yapf_format.py index 05ff6f699..2dc790ea9 100644 --- a/tests/pending/test_yapf_format.py +++ b/tests/pending/test_yapf_format.py @@ -4,11 +4,10 @@ import sys import unittest -from tests.utils import list_all_py_files -from tests.utils import CustomTestCase - from yapf.yapflib.yapf_api import FormatCode +from tests.utils import CustomTestCase, list_all_py_files + def _read_utf_8_file(filename): if sys.version_info.major == 2: ## Python 2 specific diff --git a/tests/performance_test/vgg/keras_test.py b/tests/performance_test/vgg/keras_test.py index 4b77cbea1..83694ed67 100644 --- a/tests/performance_test/vgg/keras_test.py +++ b/tests/performance_test/vgg/keras_test.py @@ -1,12 +1,14 @@ -import time import os -import psutil +import time + +import tensorflow as tf + import keras +import psutil +from exp_config import (BATCH_SIZE, LERANING_RATE, MONITOR_INTERVAL, NUM_ITERS, random_input_generator) from keras.applications.vgg16 import VGG16 from keras.backend.tensorflow_backend import set_session from keras.utils import to_categorical -import tensorflow as tf -from exp_config import random_input_generator, MONITOR_INTERVAL, NUM_ITERS, BATCH_SIZE, LERANING_RATE config = tf.ConfigProto() config.gpu_options.allow_growth = True diff --git a/tests/performance_test/vgg/pytorch_test.py b/tests/performance_test/vgg/pytorch_test.py index a81aa0be3..2849fef41 100644 --- a/tests/performance_test/vgg/pytorch_test.py +++ b/tests/performance_test/vgg/pytorch_test.py @@ -1,12 +1,14 @@ +import os +import time + +import numpy as np + +import psutil import torch import torch.nn.functional as F import torch.optim as optim +from exp_config import (BATCH_SIZE, LERANING_RATE, MONITOR_INTERVAL, NUM_ITERS, random_input_generator) from torchvision.models import vgg16 -import time -import os -import psutil -import numpy as np -from exp_config import random_input_generator, MONITOR_INTERVAL, NUM_ITERS, BATCH_SIZE, LERANING_RATE # set gpu_id 0 device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") diff --git a/tests/performance_test/vgg/tf2-autograph.py b/tests/performance_test/vgg/tf2-autograph.py index 90d2ccf0d..1349bbe3d 100644 --- a/tests/performance_test/vgg/tf2-autograph.py +++ b/tests/performance_test/vgg/tf2-autograph.py @@ -1,9 +1,11 @@ -import time import os -import psutil -from tensorflow.python.keras.applications import VGG16 +import time + import tensorflow as tf -from exp_config import random_input_generator, MONITOR_INTERVAL, NUM_ITERS, BATCH_SIZE, LERANING_RATE +from tensorflow.python.keras.applications import VGG16 + +import psutil +from exp_config import (BATCH_SIZE, LERANING_RATE, MONITOR_INTERVAL, NUM_ITERS, random_input_generator) gpus = tf.config.experimental.list_physical_devices('GPU') if gpus: diff --git a/tests/performance_test/vgg/tf2-eager.py b/tests/performance_test/vgg/tf2-eager.py index d4c78088f..428aaf86f 100644 --- a/tests/performance_test/vgg/tf2-eager.py +++ b/tests/performance_test/vgg/tf2-eager.py @@ -1,9 +1,11 @@ -import time import os -import psutil -from tensorflow.python.keras.applications import VGG16 +import time + import tensorflow as tf -from exp_config import random_input_generator, MONITOR_INTERVAL, NUM_ITERS, BATCH_SIZE, LERANING_RATE +from tensorflow.python.keras.applications import VGG16 + +import psutil +from exp_config import (BATCH_SIZE, LERANING_RATE, MONITOR_INTERVAL, NUM_ITERS, random_input_generator) gpus = tf.config.experimental.list_physical_devices('GPU') if gpus: diff --git a/tests/performance_test/vgg/tl2-autograph.py b/tests/performance_test/vgg/tl2-autograph.py index 63f553960..525f7dacf 100644 --- a/tests/performance_test/vgg/tl2-autograph.py +++ b/tests/performance_test/vgg/tl2-autograph.py @@ -1,9 +1,11 @@ -import time import os -import psutil +import time + import tensorflow as tf + +import psutil import tensorlayer as tl -from exp_config import random_input_generator, MONITOR_INTERVAL, NUM_ITERS, BATCH_SIZE, LERANING_RATE +from exp_config import (BATCH_SIZE, LERANING_RATE, MONITOR_INTERVAL, NUM_ITERS, random_input_generator) gpus = tf.config.experimental.list_physical_devices('GPU') if gpus: diff --git a/tests/performance_test/vgg/tl2-eager.py b/tests/performance_test/vgg/tl2-eager.py index fd2ef4085..81208f245 100644 --- a/tests/performance_test/vgg/tl2-eager.py +++ b/tests/performance_test/vgg/tl2-eager.py @@ -1,9 +1,11 @@ -import time import os -import psutil +import time + import tensorflow as tf + +import psutil import tensorlayer as tl -from exp_config import random_input_generator, MONITOR_INTERVAL, NUM_ITERS, BATCH_SIZE, LERANING_RATE +from exp_config import (BATCH_SIZE, LERANING_RATE, MONITOR_INTERVAL, NUM_ITERS, random_input_generator) gpus = tf.config.experimental.list_physical_devices('GPU') if gpus: diff --git a/tests/performance_test/vgg/tl2-static-autograph.py b/tests/performance_test/vgg/tl2-static-autograph.py index 0af20adb8..09f63c8ba 100644 --- a/tests/performance_test/vgg/tl2-static-autograph.py +++ b/tests/performance_test/vgg/tl2-static-autograph.py @@ -1,9 +1,11 @@ -import time import os -import psutil +import time + import tensorflow as tf + +import psutil import tensorlayer as tl -from exp_config import random_input_generator, MONITOR_INTERVAL, NUM_ITERS, BATCH_SIZE, LERANING_RATE +from exp_config import (BATCH_SIZE, LERANING_RATE, MONITOR_INTERVAL, NUM_ITERS, random_input_generator) gpus = tf.config.experimental.list_physical_devices('GPU') if gpus: diff --git a/tests/performance_test/vgg/tl2-static-eager.py b/tests/performance_test/vgg/tl2-static-eager.py index b6d5287ba..1a16e2cbf 100644 --- a/tests/performance_test/vgg/tl2-static-eager.py +++ b/tests/performance_test/vgg/tl2-static-eager.py @@ -1,9 +1,11 @@ -import time import os -import psutil +import time + import tensorflow as tf + +import psutil import tensorlayer as tl -from exp_config import random_input_generator, MONITOR_INTERVAL, NUM_ITERS, BATCH_SIZE, LERANING_RATE +from exp_config import (BATCH_SIZE, LERANING_RATE, MONITOR_INTERVAL, NUM_ITERS, random_input_generator) gpus = tf.config.experimental.list_physical_devices('GPU') if gpus: diff --git a/tests/test_activations.py b/tests/test_activations.py index 39097a63b..dc053dda5 100644 --- a/tests/test_activations.py +++ b/tests/test_activations.py @@ -4,13 +4,13 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Test_Leaky_ReLUs(CustomTestCase): diff --git a/tests/test_initializers.py b/tests/test_initializers.py index df86fd834..a5c978251 100644 --- a/tests/test_initializers.py +++ b/tests/test_initializers.py @@ -4,14 +4,14 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - -import tensorflow as tf -import tensorlayer as tl import numpy as np +import tensorflow as tf +import tensorlayer as tl from tests.utils import CustomTestCase +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + class Test_Leaky_ReLUs(CustomTestCase): diff --git a/tests/test_nlp.py b/tests/test_nlp.py index 680eeb83b..e45db5117 100644 --- a/tests/test_nlp.py +++ b/tests/test_nlp.py @@ -4,14 +4,15 @@ import os import unittest -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl - from tensorflow.python.platform import gfile -from tests.utils import CustomTestCase + import nltk +import tensorlayer as tl +from tests.utils import CustomTestCase + +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' + nltk.download('punkt') diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py index 15d4814c2..323329d63 100644 --- a/tests/utils/__init__.py +++ b/tests/utils/__init__.py @@ -1,9 +1,8 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from tests.utils.custom_layers import * +from tests.utils.custom_networks import * from tests.utils.custom_testcase import * from tests.utils.list_py_files import * from tests.utils.timeout_utils import * - -from tests.utils.custom_layers import * -from tests.utils.custom_networks import * \ No newline at end of file diff --git a/tests/utils/custom_layers/__init__.py b/tests/utils/custom_layers/__init__.py index 995a053ce..d9abe0d59 100644 --- a/tests/utils/custom_layers/__init__.py +++ b/tests/utils/custom_layers/__init__.py @@ -2,4 +2,4 @@ # -*- coding: utf-8 -*- from tests.utils.custom_layers.basic_layers import * -from tests.utils.custom_layers.inception_blocks import * \ No newline at end of file +from tests.utils.custom_layers.inception_blocks import * diff --git a/tests/utils/custom_layers/basic_layers.py b/tests/utils/custom_layers/basic_layers.py index 83f320aec..27ce5c1fc 100644 --- a/tests/utils/custom_layers/basic_layers.py +++ b/tests/utils/custom_layers/basic_layers.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import tensorflow as tf + import tensorlayer as tl __all__ = [ @@ -61,10 +62,9 @@ def activation_module(layer, activation_fn, leaky_relu_alpha=0.2, name=None): def conv_module( - prev_layer, n_out_channel, filter_size, strides, padding, is_train=True, use_batchnorm=True, activation_fn=None, - conv_init=tl.initializers.random_uniform(), - batch_norm_init=tl.initializers.truncated_normal(mean=1., - stddev=0.02), bias_init=tf.zeros_initializer(), name=None + prev_layer, n_out_channel, filter_size, strides, padding, is_train=True, use_batchnorm=True, activation_fn=None, + conv_init=tl.initializers.random_uniform(), batch_norm_init=tl.initializers.truncated_normal(mean=1., stddev=0.02), + bias_init=tf.zeros_initializer(), name=None ): if activation_fn not in ["ReLU", "ReLU6", "Leaky_ReLU", "PReLU", "PReLU6", "PTReLU6", "CReLU", "ELU", "SELU", @@ -98,10 +98,8 @@ def conv_module( def dense_module( - prev_layer, n_units, is_train, use_batchnorm=True, activation_fn=None, - dense_init=tl.initializers.random_uniform(), - batch_norm_init=tl.initializers.truncated_normal(mean=1., - stddev=0.02), bias_init=tf.zeros_initializer(), name=None + prev_layer, n_units, is_train, use_batchnorm=True, activation_fn=None, dense_init=tl.initializers.random_uniform(), + batch_norm_init=tl.initializers.truncated_normal(mean=1., stddev=0.02), bias_init=tf.zeros_initializer(), name=None ): if activation_fn not in ["ReLU", "ReLU6", "Leaky_ReLU", "PReLU", "PReLU6", "PTReLU6", "CReLU", "ELU", "SELU", diff --git a/tests/utils/custom_layers/inception_blocks.py b/tests/utils/custom_layers/inception_blocks.py index 89d2640d4..90c38a9a3 100644 --- a/tests/utils/custom_layers/inception_blocks.py +++ b/tests/utils/custom_layers/inception_blocks.py @@ -2,8 +2,8 @@ # -*- coding: utf-8 -*- import tensorflow as tf -import tensorlayer as tl +import tensorlayer as tl from tests.utils.custom_layers.basic_layers import conv_module __all__ = [ diff --git a/tests/utils/custom_networks/__init__.py b/tests/utils/custom_networks/__init__.py index 81dd159ba..e245d6ac1 100644 --- a/tests/utils/custom_networks/__init__.py +++ b/tests/utils/custom_networks/__init__.py @@ -1,4 +1,4 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from tests.utils.custom_networks.inceptionv4 import * \ No newline at end of file +from tests.utils.custom_networks.inceptionv4 import * diff --git a/tests/utils/custom_networks/inceptionv4.py b/tests/utils/custom_networks/inceptionv4.py index bac2ae897..e9895eec0 100644 --- a/tests/utils/custom_networks/inceptionv4.py +++ b/tests/utils/custom_networks/inceptionv4.py @@ -3,20 +3,15 @@ import os -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' - import tensorflow as tf -import tensorlayer as tl -from tests.utils.custom_layers.basic_layers import conv_module -from tests.utils.custom_layers.basic_layers import dense_module - -from tests.utils.custom_layers.inception_blocks import block_inception_a -from tests.utils.custom_layers.inception_blocks import block_inception_b -from tests.utils.custom_layers.inception_blocks import block_inception_c +import tensorlayer as tl +from tests.utils.custom_layers.basic_layers import conv_module, dense_module +from tests.utils.custom_layers.inception_blocks import ( + block_inception_a, block_inception_b, block_inception_c, block_reduction_a, block_reduction_b +) -from tests.utils.custom_layers.inception_blocks import block_reduction_a -from tests.utils.custom_layers.inception_blocks import block_reduction_b +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' __all__ = ['InceptionV4_Network']