Skip to content

Commit 3a44af1

Browse files
committed
[TEST] TensorFlow 10, 11 Python 2, 3
1 parent 037d2a7 commit 3a44af1

10 files changed

+45
-20
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ If you already had the pre-requisites ready, the simplest way to install TensorL
3838

3939

4040
```bash
41-
[for stable version] pip install tensorlayer==1.2.2
41+
[for stable version] pip install tensorlayer==1.2.3
4242
[for master version] pip install git+https://github.com/zsdonghao/tensorlayer.git
4343
```
4444

data/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
from __future__ import absolute_import
3+
4+
5+
from . import imagenet_classes
6+
# from . import

tensorlayer/layers.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -2671,15 +2671,22 @@ def __init__(
26712671
layer = None,
26722672
slim_layer = None,
26732673
slim_args = {},
2674-
name ='slim_layer',
2674+
name ='InceptionV3',
26752675
):
26762676
Layer.__init__(self, name=name)
26772677
self.inputs = layer.outputs
26782678
print(" tensorlayer:Instantiate SlimNetsLayer %s: %s" % (self.name, slim_layer.__name__))
26792679

2680-
with tf.variable_scope(name) as vs:
2681-
net, end_points = slim_layer(self.inputs, **slim_args)
2682-
slim_variables = tf.get_collection(tf.GraphKeys.VARIABLES, scope=vs.name)
2680+
# with tf.variable_scope(name) as vs:
2681+
# net, end_points = slim_layer(self.inputs, **slim_args)
2682+
# slim_variables = tf.get_collection(tf.GraphKeys.VARIABLES, scope=vs.name)
2683+
2684+
net, end_points = slim_layer(self.inputs, **slim_args)
2685+
2686+
slim_variables = tf.get_collection(tf.GraphKeys.VARIABLES, scope=name)
2687+
if slim_variables == []:
2688+
print("No variables found under %s : the name of SlimNetsLayer should be matched with the begining of the ckpt file, see tutorial_inceptionV3_tfslim.py for more details" % name)
2689+
26832690

26842691
self.outputs = net
26852692

tensorlayer/visualize.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def W(W=None, second=10, saveable=True, shape=[28,28], name='mnist', fig_idx=239
5858
# feature = np.zeros_like(feature)
5959
plt.imshow(np.reshape(feature ,(shape[0],shape[1])),
6060
cmap='gray', interpolation="nearest")#, vmin=np.min(feature), vmax=np.max(feature))
61-
plt.title(name)
61+
# plt.title(name)
6262
# ------------------------------------------------------------
6363
# plt.imshow(np.reshape(W[:,count-1] ,(np.sqrt(size),np.sqrt(size))), cmap='gray', interpolation="nearest")
6464
plt.gca().xaxis.set_major_locator(plt.NullLocator()) # distable tick
@@ -223,11 +223,11 @@ def images2d(images=None, second=10, saveable=True, name='images', dtype=None,
223223
plt.imshow(
224224
np.reshape(images[count-1,:,:], (n_row, n_col)),
225225
cmap='gray', interpolation="nearest")
226-
plt.title(name)
226+
# plt.title(name)
227227
elif n_color == 3:
228228
plt.imshow(images[count-1,:,:],
229229
cmap='gray', interpolation="nearest")
230-
plt.title(name)
230+
# plt.title(name)
231231
else:
232232
raise Exception("Unknown n_color")
233233
plt.gca().xaxis.set_major_locator(plt.NullLocator()) # distable tick

tutorial_generate_text.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# Copyright 2016 TensorLayer. All Rights Reserved.
1+
#! /usr/bin/python
2+
# -*- coding: utf8 -*-
3+
4+
5+
6+
# Copyright 2016 TensorLayer. All Rights Reserved.
27
#
38
# Licensed under the Apache License, Version 2.0 (the "License");
49
# you may not use this file except in compliance with the License.
@@ -264,7 +269,7 @@ def inference(x, is_training, num_steps, reuse=None):
264269
network = tl.layers.DropoutLayer(network, keep=keep_prob, name='drop1')
265270
network = tl.layers.RNNLayer(network,
266271
cell_fn=tf.nn.rnn_cell.BasicLSTMCell,
267-
cell_init_args={'forget_bias': 0.0},# 'state_is_tuple': True},
272+
cell_init_args={'forget_bias': 0.0, 'state_is_tuple': True},
268273
n_hidden=hidden_size,
269274
initializer=tf.random_uniform_initializer(-init_scale, init_scale),
270275
n_steps=num_steps,
@@ -275,7 +280,7 @@ def inference(x, is_training, num_steps, reuse=None):
275280
network = tl.layers.DropoutLayer(network, keep=keep_prob, name='drop2')
276281
network = tl.layers.RNNLayer(network,
277282
cell_fn=tf.nn.rnn_cell.BasicLSTMCell,
278-
cell_init_args={'forget_bias': 0.0}, # 'state_is_tuple': True},
283+
cell_init_args={'forget_bias': 0.0, 'state_is_tuple': True},
279284
n_hidden=hidden_size,
280285
initializer=tf.random_uniform_initializer(-init_scale, init_scale),
281286
n_steps=num_steps,

tutorial_inceptionV3_tfslim.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def print_prob(prob):
100100
# 'reuse' : None,
101101
# 'scope' : 'InceptionV3'
102102
},
103-
name=''
103+
name='InceptionV3' # <-- the name should be the same with the ckpt model
104104
)
105105
saver = tf.train.Saver()
106106

tutorial_mnist.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ def main_test_layers(model='relu'):
103103

104104
params = network.all_params
105105
# train
106-
n_epoch = 1
106+
n_epoch = 100
107107
batch_size = 128
108108
learning_rate = 0.0001
109-
print_freq = 10
109+
print_freq = 5
110110
train_op = tf.train.AdamOptimizer(learning_rate, beta1=0.9, beta2=0.999,
111111
epsilon=1e-08, use_locking=False).minimize(cost)
112112

tutorial_tfrecord.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
import tensorflow as tf
66
import tensorlayer as tl
7-
import os
7+
import numpy as np
88
from PIL import Image
99
import io
10+
import os
1011

1112

1213
"""
@@ -67,7 +68,7 @@
6768
label = example.features.feature['label'].int64_list.value
6869
## converts a image from bytes
6970
image = Image.frombytes('RGB', (224, 224), img_raw[0])
70-
tl.visualize.frame(image, second=0.5, saveable=False, name='frame', fig_idx=1283)
71+
tl.visualize.frame(np.asarray(image), second=0.5, saveable=False, name='frame', fig_idx=1283)
7172
print(label)
7273

7374

tutorial_tfrecord2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
## Visualize a image
4646
# tl.visualize.frame(np.asarray(img, dtype=np.uint8), second=1, saveable=False, name='frame', fig_idx=1236)
4747
label = int(y_train[index])
48-
print(label)
48+
# print(label)
4949
## Convert the bytes back to image as follow:
5050
# image = Image.frombytes('RGB', (32, 32), img_raw)
5151
# image = np.fromstring(img_raw, np.float32)

tutorial_tfrecord3.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def _bytes_feature_list(values):
117117
c = tf.contrib.learn.run_n(features, n=1, feed_dict=None)
118118
from PIL import Image
119119
im = Image.frombytes('RGB', (299, 299), c[0]['image/img_raw'])
120-
tl.visualize.frame(im, second=1, saveable=False, name='frame', fig_idx=1236)
120+
tl.visualize.frame(np.asarray(im), second=1, saveable=False, name='frame', fig_idx=1236)
121121
c = tf.contrib.learn.run_n(sequence_features, n=1, feed_dict=None)
122122
print(c[0])
123123

@@ -334,10 +334,16 @@ def prefetch_input_data(reader,
334334
img = tf.decode_raw(context["image/img_raw"], tf.uint8)
335335
img = tf.reshape(img, [height, width, 3])
336336
img = tf.image.convert_image_dtype(img, dtype=tf.float32)
337+
# for TensorFlow 0.10
338+
# img = tf.image.resize_images(img,
339+
# new_height=resize_height,
340+
# new_width=resize_width,
341+
# method=tf.image.ResizeMethod.BILINEAR)
342+
# for TensorFlow 0.11
337343
img = tf.image.resize_images(img,
338-
new_height=resize_height,
339-
new_width=resize_width,
344+
size=(resize_height, resize_width),
340345
method=tf.image.ResizeMethod.BILINEAR)
346+
341347
# Crop to final dimensions.
342348
if is_training:
343349
img = tf.random_crop(img, [height, width, 3])

0 commit comments

Comments
 (0)