2016年8月20日 星期六

[Tensorflow] Learning Note: Try to downsize graph.pb model



As the previous tutorial "Loading a tensorflow graph with the C++ API by using Mnist", I introduce how to use C++ API to load tensorflow graph.
In this topic, I will introduce more details about how to downsize training model if we want to use it on device.

(NOTE: Tensorflow also supports the mobile version.
I have not studied yet, but I think it is a good reference for you. )


Downsize model by using freeze graph

Why freezing ?

In Tensorflow-tool-develop-freezing said that:
"What this does is load the GraphDef, pull in the values for all the variables from the latest checkpoint file, and then replace each Variable op with a Const that has the numerical data for the weights stored in its attributes It then strips away all the extraneous nodes that aren't used for forward inference, and saves out the resulting GraphDef into an output file

How to freeze graph ?

Use the freez_graph.py, and run the following commands:
bazel build tensorflow/python/tools:freeze_graph && \
bazel-bin/tensorflow/python/tools/freeze_graph \
--input_graph=some_graph_def.pb \
--input_checkpoint=model.ckpt-8361242 \
--output_graph=/tmp/frozen_graph.pb --output_node_names=softmax

In my example on github (https://github.com/JackyTung/tensorgraph)
I will use graph.pb and model.ckpt to generate freeze graph
bazel build tensorflow/python/tools:freeze_graph && \
bazel-bin/tensorflow/python/tools/freeze_graph \
--input_graph=graph.pb \
--input_checkpoint=model.ckpt \
--output_graph=/tmp/frozen_graph.pb --output_node_names=softmax
Note:
The model size will have not so big different in the mnist example.
However, once using more complex example, you will see the power of freeze_graph.py.


How to extract tensors from ckpt file

Following steps:
$ cd tensorflow/tensorflow/python/tools

// list all tensors
$ python inspect_checkpoint.py --file_name=$your_ckpt_file_path

// print the value from specific tensor
$ python inspect_checkpoint.py --file_name=$your_ckpt_file_path  --tensor_name=$specific_tensor
Following demo is from my example:
python inspect_checkpoint.py --file_name=$your_ckpt_file_path


python inspect_checkpoint.py --file_name=$your_ckpt_file_path  --tensor_name=$specific_tensor


Be honestly, I am a new beginner in machine learning.
If I wrote something wrong or have a better suggestion, leave message to me.
I'll revise and update my article :)

2016年8月14日 星期日

[loggly] Learning notes: Comments from a 30-day free trial user for machine learning usage scenarios



This is a reference for the machine learning developers that want to choose loggly to 
monitor logs such as :
1. Training records (iter, epoch, accuracy, precision, recall ...)
2. CPU, Memory, GPU usage
3. Machines status (training on multi-machine)

My Requirements:
1.  Can figure out training logs sources (logs are sent by which machines, gpu, or task)
2.  Can view raw logs when run time training
3.  Can set alerts by specific conditions (ex: CPU, Mem, GPU alerts)
4.  Can integrate alerts with Slack or Hipchat
5.  Can show dashboard and query dashboard by customed time interval (ex: 1hr, 2hr, 7days)
6.  Lower price

Loggly vs Requirements:
1. Yes
Loggly have powerful searching ability and can manage logs from any source.
I use fluentd to collect logs, and then send logs to loggly by specific tags.
loggly integrate fluentd )

<match your_match>
    type loggly
    loggly_url https://logs-01.loggly.com/inputs/TOKEN/tag/fluentd
</match>
TOKEN:  your customer token from the source setup page
fluentd: can change tag name here!! example fluentd configuration to monitor training logs and sys logs by task:

<match training_logs_match>
    type loggly
    loggly_url https://logs-01.loggly.com/inputs/TOKEN/tag/TrainingLogs-${Task}
</match>

<match sys_logs_match>
    type loggly
    loggly_url https://logs-01.loggly.com/inputs/TOKEN/tag/SysLogs-${Task}
</match>


Then, we can view specific-tag logs in summary dashboard
2. Yes
Beside, loggly can custom time interval in search.

3. Yes.
The operating logic in loggly is
(1) search by specific condition
(2) save your custom search query
(3) set alerts based on custom search query

The operations on "How to search" and "How to set alerts" are not friendly for the beginning user.
I hope Loggly team can use more video to introduce above operations.


4. Yes
Check following links:
https://www.loggly.com/docs/send-loggly-alerts-hipchat/
https://www.loggly.com/docs/slack-alerts/

5. No
I think this is the main drawback in loggly now.
In most usage, I may want to check the number of events before 1hr, 2hr,.. 7days.
It is very weird that can not custom time interval.
I hope Loggly team can add this feature in the future.


6.  Lower price ?
The price is a little expensive for my use case.
It depends on your case.
If you think loggly pro is affordable for you, why not ? :)
If you want to save money, maybe EFK(Elasticsearch, Fluentd, Kibana) is another a good solution.


volume (GB/day)
retention (days)
Monthly
Annual
1
15
109/month
99/month
1
30
149/month
129/month
2
15
149/month
129/month
2
30
195/month
179/month
4
15
225/month
199/month

Without pro, can not custom dashboards, set alerts and integrate alerts with hipchat.





技術提供:Blogger.