Exemplo n.º 1
0
import torch
from torch import nn
import IStudio as iv

studio = iv.AIStudio("pytorch")

model = nn.Sequential()
model.add_module('W0', nn.Linear(8, 16))
model.add_module('tanh', nn.Tanh())
model.add_module('W1', nn.Linear(16, 1))

x = torch.randn(1, 8)

studio.RecordGraphDef(model(x), "speech",
                      dict(list(model.named_parameters()) + [('x', x)]))
Exemplo n.º 2
0
def main(_):
    """get ai studio with tensorflow as backend"""
    studio = iv.AIStudio("tensorflow")
 
    # Import data
    mnist = input_data.read_data_sets(studio.DataFolder, one_hot=True)
    # Create the model

    x = tf.placeholder(tf.float32, [None, 784], name="x")
    W = tf.Variable(tf.zeros([784, 10]), name="W")
    b = tf.Variable(tf.zeros([10]), name="b")
    y = tf.matmul(x, W) + b

    # Define loss and optimizer
    y_ = tf.placeholder(tf.float32, [None, 10])

    # The raw formulation of cross-entropy,
    #
    # tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(tf.nn.softmax(y)),
    #                                 reduction_indices=[1]))
    #
    # can be numerically unstable.
    #
    # So here we use tf.nn.softmax_cross_entropy_with_logits on the raw
    # outputs of 'y', and then average across the batch.
    cross_entropy = tf.reduce_mean(
        tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y))
    train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)

    sess = tf.InteractiveSession()
    tf.global_variables_initializer().run()

    #record computation graph
    studio.RecordGraphDef(sess.graph_def, "softmax")
    
    studio.AddRecordVariable(W, "w")
    studio.AddRecordImage(x, "input image")
    studio.AddRecordScalar(cross_entropy, "loss")
    
    summary = studio.GetRecordList()
    
    # Train
    for _ in range(20):
        batch_xs, batch_ys = mnist.train.next_batch(100)
        c, ww, _ = sess.run([cross_entropy, W, train_step], feed_dict={x: batch_xs, y_: batch_ys})
        
        """record data for real-time view"""
        studio.RecordVariable(ww, "w")
        studio.RecordImage(batch_xs, "input image")
        studio.RecordScalar(c, "loss")
        #studio.SaveRecordList(summary_result)
    
    # Test trained model
    correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
    ac = sess.run(accuracy, feed_dict={x: mnist.test.images,
                                      y_: mnist.test.labels})
    #record results for plot
    studio.RecordScalar(ac, "accuracy(true)")
    studio.RecordScalar(1.0 - ac, "accuracy(false)")
   
    #inference
    draw = iv.IPDraw("Draw2D-1")
    image3 = iv.IPGraph("Image-3")
    plot3 = image3.Plots(0)
    print("Start inference, draw number using draw pad")
    for k in range(600):
        # get draw image
        image = draw.GetDrawImage(28*28, 28, 28, 1, False)
        image.astype(np.float32)
        image /= (-image.max())
        image += 1
        #draw the normalized image
        plot3.ImageColor(image, 28, 28)
        xx = np.expand_dims(image, axis=0)
        inference = tf.argmax(y, 1)
        yy, results = sess.run([y, inference], feed_dict={x: xx})
        print("You drawing is:", results)
        sleep(1)
Exemplo n.º 3
0
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os
import sys
import tensorflow as tf
import numpy as np
import IStudio as iv

studio = iv.AIStudio("tensorflow")
filename = inspect.getframeinfo(inspect.currentframe()).filename
dir_path = os.path.dirname(os.path.abspath(filename))
mobile_file = dir_path + "\\rcnn_ssdlite_mobile.pb"
resnet_file = dir_path + "\\rcnn_resnet50.pb"
maskrnn_file = dir_path + "\\mask_rcnn_inceptionv2.pb"
label_file = dir_path + "\\mscoco_label_map.txt"
height, width = 800, 800
NUM_CLASSES = 90
max_boxes_to_draw = 100

#load label
with open(label_file) as f:
    label_list = f.read().splitlines()

camera = iv.IPCamera("Camera-1")
camera.ClearBoundingBox()
input_img = np.zeros((1, height, width, 3), dtype=np.uint8)

#load forzen graph
studio.LoadGraphDef(maskrnn_file)
Exemplo n.º 4
0
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import sys
import IStudio as vi
import numpy as np

s = vi.AIStudio("tensorflow")

print(sys.path)