29
Fri, Nov
0 New Articles

Open-Source Tools for Watson, Part 3

Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

TensorFlow. Sounds like something from a Guardians of the Galaxy movie, maybe something that Rocket Raccoon might use. And Caffe? What’s that? Hint: This article is about AI tools, not coffee.

By Dave Shirey  

In last month’s exciting episode, we looked at what a model was and what different types of models we could find. This month, we’ll look at two tools that can be used to set up models for you that can then be used in an AI project: TensorFlow and Caffe.

Caffe

Let’s start with Caffe (Convolutional Architecture for Fast Feature Embedding). Unfortunately, while everyone agrees that Caffe is simple to use (relatively speaking, of course, since nothing in AI is really simple), the different flavors of Caffe can be a bit confusing to at first.

The original Caffe, called just Caffe, is a free and open-source piece of software written in C+. Like most AI products, Caffe does not do everything. Specifically, it’s primarily oriented around image-recognition projects.

As the Caffe website so eloquently puts it, Caffe is built for expressiveness, speed, and modularity. Expressiveness? Simply put, Expressive architecture allows you to develop or configure new models based on the configuration, rather than by hard coding things in the software itself.

Because it is open source and has had over 1000 downloads, a number of users have enhanced and expanded it and have uploaded their modifications to the mother ship. The result is a product that remains near the cutting edge of AI image projects.

In addition, there is an active Caffe user group, which is very important as you move forward. It’s helpful to have a group of people using the same software who you can communicate with.

Caffe models can process 60 million images a day, averaging 1 millisecond to access the image and 4 milliseconds for the learning process. This makes Caffe one of the fastest image-recognition models currently available.

Caffe2 is the next generation of Caffe. It’s meant not to replace the original but to expand it. One of the main benefits of Caffe2 is its support for mobile in the AI process. It also provides “operators,” which are like the “layers” in Caffe but are more flexible in terms of how you can use them. Layers/operators contain the basic logic required to calculate the output that will be generated, based on the various input features. While Caffe has some of that, there’s more in Caffe2, and you also have the ability to create your own custom operators.

And, if that’s not enough, the Caffe2 website indicates that the product is being rolled into PyTouch, a Python library.

These products provide a large number of pretrained models (found in GitHub) that you can bring in and use if the shoe fits.

If there is a negative related to Caffe, it’s that it’s a little light on documentation, not surprising for an open-source product. But it does have a very large and enthusiastic set of users, and they have written a plethora of articles and blog posts designed to help you with whatever you’re struggling with.

TensorFlow

TensorFlow is the big gorilla of this genre, having been developed by the Google Brain team for use within Google before being released to the open-source world.

It’s another product that lets you define a model, infuse it with a particular statistical process, and then start your data training process.

The home for TensorFlow, tensorflow.org, is a storehouse of information, not just about the product but about Machine Learning in general. That’s a good place to start as you begin to learn more about AI.

In terms of production, TensorFlow can run through JavaScript, or do mobile with iOS, Android, Edge TPU, and Raspberry Pi.

The real question is what types of models TensorFlow supports. That is, we saw above that Caffe specializes in image-recognition modeling. TensorFlow also does that, as well as text and voice recognition. And, of course, it allows you to do your own thing and develop a model that is unique to your situation.

What is that like (writing your own model)? Well, to be honest, it’s a lot of code, but the TensorFlow site gives you plenty of help in terms of how to do it, although there’s no doubt that it’s not for the faint-hearted (see the below code; the first is for beginners, the second for experts).

For beginners:

import tensorflow as tf
mnist = tf.keras.datasets.mnist

(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train /
255.0, x_test / 255.0

model = tf.keras.models.
Sequential([
  tf.keras.layers.
Flatten(input_shape=(28, 28)),
  tf.keras.layers.
Dense(128, activation='relu'),
  tf.keras.layers.
Dropout(0.2),
  tf.keras.layers.
Dense(10, activation='softmax')
])

model.compile(optimizer=
'adam',
              loss=
'sparse_categorical_crossentropy',
              metrics=[
'accuracy'])

model.fit(x_train, y_train, epochs=
5)
model.evaluate(x_test, y_test)

For more-advanced users:

class MyModel(tf.keras.Model):
 
def __init__(self):
   
super(MyModel, self).__init__()
   
self.conv1 = Conv2D(32, 3, activation='relu')
   
self.flatten = Flatten()
   
self.d1 = Dense(128, activation='relu')
   
self.d2 = Dense(10, activation='softmax')

 
def call(self, x):
    x =
self.conv1(x)
    x =
self.flatten(x)
    x =
self.d1(x)
   
return self.d2(x)
model =
MyModel()

with tf.GradientTape() as tape:
  logits = model(images)
  loss_value = loss(logits, labels)
grads = tape.gradient(loss_value, model.trainable_variables)
optimizer.apply_gradients(zip(grads, model.trainable_variables))

TensorFlow has a ton of documentation available on its site. There’s no shortage of info, and its user community has enhanced this documentation with many posts and articles.

So Which Do You Choose?

Of course, you must know that I’m not going to give a recommendation. Never get yourself involved in an unnecessary lawsuit, I say. Plus, it’s not an easy decision.

First, it depends on your model needs. What business problem are you trying to solve and what type of data will you be using in your training?

Second, you may want to consider the size of your endeavor. Caffe seems to be the acknowledged leader in terms of speed, although to get the maximum output you should be using GPU rather than CPU. If you don’t know the difference (as I did not), GPU is a type of chip that was originally designed for gaming and all that stuff. CPU is the more standard type of chip. Needless to say, GPU can beat the pants off of CPU, and it’s becoming increasingly important in the AI world, where speed is important. You can either build or buy GPU-based machines or use AWS to create a server for your GPU needs.  

Third, it depends somewhat on your technical level. Developing models in TensorFlow is definitely much more code-oriented than Caffe, which uses an abstraction layer to let you set up your models in something that looks very much like CSS code. For example:

# train_val.prototxt

name: "MyModel"

layer {  

name: "data"  

type: "Data"  

top: "data"  

top: "label"  

include

{    

phase: TRAIN  

}  

transform_param {    

mirror: false    

crop_size: 227    

mean_file: "data/train_mean.binaryproto" # location of the training data mean  

}  

data_param {    

source: "data/train_lmdb" # location of the training samples    

batch_size: 128 # how many samples are grouped into one mini-batch     backend: LMDB  

} }

layer {  

name: "data"  

type: "Data"  

top: "data"    è etc.

In the end, you’ll have to look carefully at what you’re trying to do, the level of technical resources you have available, and maybe your astrological sign. I mean, it can’t hurt, right?

David Shirey

David Shirey is president of Shirey Consulting Services, providing technical and business consulting services for the IBM i world. Among the services provided are IBM i technical support, including application design and programming services, ERP installation and support, and EDI setup and maintenance. With experience in a wide range of industries (food and beverage to electronics to hard manufacturing to drugs--the legal kind--to medical devices to fulfillment houses) and a wide range of business sizes served (from very large, like Fresh Express, to much smaller, like Labconco), SCS has the knowledge and experience to assist with your technical or business issues. You may contact Dave by email at This email address is being protected from spambots. You need JavaScript enabled to view it. or by phone at (616) 304-2466.


MC Press books written by David Shirey available now on the MC Press Bookstore.

21st Century RPG: /Free, ILE, and MVC 21st Century RPG: /Free, ILE, and MVC
Boost your productivity, modernize your applications, and upgrade your skills with these powerful coding methods.
List Price $69.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: