print('epoch %4d, cost = %.9f' % (epoch, avg_cost)) print("Accuracy: %f" % acc.eval(session=sess, feed_dict={ x: mnist.test.images, y: mnist.test.labels })) summary_writer.close() ### Examine layers # A red/black/blue colormap cdict = { 'red': [(0.0, 1.0, 1.0), (0.25, 1.0, 1.0), (0.5, 0.0, 0.0), (1.0, 0.0, 0.0)], 'green': [(0.0, 0.0, 0.0), (1.0, 0.0, 0.0)], 'blue': [(0.0, 0.0, 0.0), (0.5, 0.0, 0.0), (0.75, 1.0, 1.0), (1.0, 1.0, 1.0)] } redblue = matplotlib.colors.LinearSegmentedColormap('red_black_blue', cdict, 256) wts = W.eval(sess) for i in range(0, 5): im = wts.flatten()[i::10].reshape((28, -1)) plt.imshow(im, cmap=redblue, clim=(-1.0, 1.0)) plt.colorbar() print("Digit %d" % i) plt.show() ### Explore using Tensorboard utils.start_tensorboard(logs_path)
summary_writer.close() ### Examine layers # A red/black/blue colormap cdict = { 'red': [(0.0, 1.0, 1.0), (0.25, 1.0, 1.0), (0.5, 0.0, 0.0), (1.0, 0.0, 0.0)], 'green': [(0.0, 0.0, 0.0), (1.0, 0.0, 0.0)], 'blue': [(0.0, 0.0, 0.0), (0.5, 0.0, 0.0), (0.75, 1.0, 1.0), (1.0, 1.0, 1.0)] } redblue = matplotlib.colors.LinearSegmentedColormap('red_black_blue', cdict, 256) wts = W.eval(sess) for i in range(0, 5): im = wts.flatten()[i::10].reshape((28, -1)) plt.imshow(im, cmap=redblue, clim=(-1.0, 1.0)) plt.colorbar() print("Digit %d" % i) plt.show() ### Explore using Tensorboard utils.start_tensorboard(logs_path, iframe=False) # Script completed! Click on the above link! # ====================== # # This example code showcases: # - Ability to install and use custom packages (e.g. `pip search tensorflow`)
import utils init_engine() ##### 1. __define location of Inceptionv3 frozen model,the graph input/output names and labels.__ inputs = ['input'] outputs = ['InceptionV3/Predictions/Reshape_1'] tf_model = '/home/cdsw/jumpstart/frozen_models/inception_v3_2016_08_28_frozen.pb' tf_labels = "/home/cdsw/jumpstart/frozen_models/imagenet_slim_labels.txt" ##### 2. __Load the tensorflow model as an BigDL model__ model = Model.load_tensorflow(tf_model, inputs, outputs, bigdl_type="float") ##### 3. __(Optional) save it in a folder so that it can be viewed using tensorboard __ model.save_graph_topology("/tmp/bigdl_summaries/") utils.start_tensorboard("/tmp/bigdl_summaries/") ##### should be able to select tensorboard from the cdsw project menu then graphs from the tensorboard menu Image('images/bigdl_tensorflow_imported_graphview.png') with open(tf_labels,"r") as lbls: label_lines = [line.rstrip() for line in lbls] testset = {'lemon':'lemon.jpg','squirrel':'squirrel.jpg',"basketball game":"basketball_game.jpg"} predicted =[] for (lbl,imgpath) in testset.iteritems(): test_image = image.load_img(imgpath,target_size=(299,299)) test_image = image.img_to_array(test_image) x = np.expand_dims(test_image, axis=0) x = preprocess_input(x) res = model.predict(x) reslbl = { label_lines[k]:v for k,v in enumerate(res[0]) }