1
00:00:00,240 --> 00:00:06,080
In this lesson we will convert our model our tensor flow model to tensor flow.

2
00:00:06,120 --> 00:00:07,180
Yes.

3
00:00:07,470 --> 00:00:13,170
And in the process we're going to learn how to set up a separate Python environment and also switch

4
00:00:13,170 --> 00:00:15,520
between development environments.

5
00:00:15,540 --> 00:00:20,460
Now we're gonna do that well regular tensor flow models can't run in the browser.

6
00:00:20,460 --> 00:00:26,520
For that our models need to be in the tensor flow J.S. format and this means that we have to convert

7
00:00:26,760 --> 00:00:33,770
our saved model and its PDB files and its variable files into a different format.

8
00:00:33,810 --> 00:00:35,440
The tensor flow J.S. format.

9
00:00:35,550 --> 00:00:37,290
So how we're gonna do that.

10
00:00:37,290 --> 00:00:42,930
Well as always our first stop is going to be the official documentation.

11
00:00:42,930 --> 00:00:49,590
So if I check out tensor flows website here under a model conversion I can see quite a lengthy and descriptive

12
00:00:49,620 --> 00:00:50,400
article.

13
00:00:50,400 --> 00:00:55,830
And as you can see here there are different instructions depending on your starting point.

14
00:00:55,890 --> 00:00:57,720
So there's a slightly different way to go about it.

15
00:00:57,720 --> 00:01:00,840
If you have a saved model versus if you have a Caris model.

16
00:01:00,890 --> 00:01:05,180
This is if you have a tensor flow hub model and because we're working with the saved model we're going

17
00:01:05,170 --> 00:01:12,240
to be making use of this tensor flow J.S. converter and this tensor flow JS converter lives on this

18
00:01:12,240 --> 00:01:18,270
getup repo right here and there's some instructions below but I'm think there is slightly complicated.

19
00:01:18,270 --> 00:01:23,340
So when I walk you through them the thing is and I'm going to say this upfront it can be a little bit

20
00:01:23,340 --> 00:01:25,150
tricky to get this to work.

21
00:01:25,200 --> 00:01:30,510
It certainly was for me and the reason is is that there are a lot of moving parts that all have to play

22
00:01:30,510 --> 00:01:37,680
nice with each other the kind of moving parts I'm talking about are tensor flow tensor flow yes Charisse

23
00:01:37,980 --> 00:01:39,180
and python.

24
00:01:39,180 --> 00:01:44,010
All of these have specific versions that the converter cares about and all of these different parts.

25
00:01:44,010 --> 00:01:47,120
Update periodically but not at the same time.

26
00:01:47,220 --> 00:01:52,770
So I actually had a little bit of trouble getting this to work at first because I ran into some incompatibilities

27
00:01:52,800 --> 00:01:57,660
between the different versions of python and the converter and the converter and versions of Karras

28
00:01:58,020 --> 00:01:59,500
and some other things.

29
00:01:59,550 --> 00:02:02,560
So this was actually a little bit difficult to troubleshoot.

30
00:02:02,760 --> 00:02:08,880
So as a little bit of a backup I'm going to add my output files under the lesson resources so if you

31
00:02:08,880 --> 00:02:14,490
run into any problems and you're having difficulty troubleshooting it you have those available and can

32
00:02:14,490 --> 00:02:19,800
continue on with the module so the question at this point is what's the solution.

33
00:02:19,840 --> 00:02:25,240
How do we get all these components and all the versioning to play nice with each other and to work.

34
00:02:25,240 --> 00:02:28,750
How do we lock down all the versions in a controlled way.

35
00:02:30,040 --> 00:02:33,800
And the answer to this problem is we need a separate environment.

36
00:02:33,970 --> 00:02:39,070
We need a special environment just for the tensor flow GSK converter.

37
00:02:39,070 --> 00:02:43,920
In other words the 10th floor JS converter will use its own version of Python.

38
00:02:44,020 --> 00:02:49,240
It's gonna use a very particular version of Caris and it's gonna use particular versions of all the

39
00:02:49,240 --> 00:02:56,020
other dependencies including its own version of tensor flow Jesus and all these versions may not be

40
00:02:56,110 --> 00:02:59,420
the latest versions but they're the ones that are gonna work.

41
00:02:59,440 --> 00:03:02,080
So how do we set up the separate environment.

42
00:03:02,170 --> 00:03:06,050
The good news is is that Anaconda makes this really really easy for us.

43
00:03:06,160 --> 00:03:13,030
It makes it really easy to set up separate Python environments in parallel and allowing you to switch

44
00:03:13,030 --> 00:03:14,290
in between them.

45
00:03:14,290 --> 00:03:19,750
If you look at the documentation right here we get a little bit of a description of how to go about

46
00:03:19,750 --> 00:03:20,340
it.

47
00:03:20,380 --> 00:03:23,330
Here we can see how we can go about creating an environment.

48
00:03:23,470 --> 00:03:29,830
And here we see how to activate and deactivate an environment all of these instructions pertain to the

49
00:03:29,830 --> 00:03:32,640
terminal or the windows command prompt.

50
00:03:32,660 --> 00:03:38,990
They're all we have to do is type in something like this kinda create which is the command.

51
00:03:39,220 --> 00:03:46,250
Then we provide the environment name that we want to create and then we provide a python version.

52
00:03:46,330 --> 00:03:54,220
So in our case we're gonna write kinda create hyphen and converter underscore environment and then Python

53
00:03:54,280 --> 00:03:56,140
equals three point six.

54
00:03:56,140 --> 00:04:03,400
Now you can actually do this in the anaconda Navigator as well if you prefer using agree as opposed

55
00:04:03,400 --> 00:04:10,510
to the terminal or the command prompt if you fire up the anaconda navigator and you click on environments

56
00:04:10,540 --> 00:04:11,750
right here.

57
00:04:11,770 --> 00:04:14,650
Then what you can see is you can simply click on this button here.

58
00:04:14,680 --> 00:04:23,070
What's this create then you can provide a name converter underscore environment and then you can select

59
00:04:23,080 --> 00:04:27,250
the python version right here and we're gonna be using three point six.

60
00:04:27,250 --> 00:04:32,440
Now at this point you can either click Create or if you want to follow along with me you can do it in

61
00:04:32,440 --> 00:04:34,210
the terminal on Windows.

62
00:04:34,330 --> 00:04:38,150
You'd be using the anaconda prompt which looks like this.

63
00:04:38,340 --> 00:04:46,410
Here you simply type kinda create hyphen n and then you provide the name of the environment you want

64
00:04:46,410 --> 00:04:57,100
to create converter underscore and space python is equal to three point six so I've got my line wrapping

65
00:04:57,100 --> 00:05:01,180
around him but it's all a single line that looks something like this.

66
00:05:01,180 --> 00:05:05,800
Make sure you don't have any typos and you're indeed using python version three point six.

67
00:05:05,800 --> 00:05:06,910
That's quite important.

68
00:05:06,910 --> 00:05:08,320
So hitting enter here.

69
00:05:08,380 --> 00:05:11,400
You can actually see that it's working in the background.

70
00:05:11,680 --> 00:05:15,910
And as it's doing this it's asking us whether or not we want to proceed.

71
00:05:15,910 --> 00:05:21,460
So type Y and hit enter and then you can keep an eye on the anaconda navigator even if you've got it

72
00:05:21,490 --> 00:05:26,810
open and you should actually see it working and creating that second environment.

73
00:05:28,640 --> 00:05:29,090
Brilliant.

74
00:05:29,540 --> 00:05:31,500
So now that you've set up this environment.

75
00:05:31,520 --> 00:05:32,630
How do you activate it.

76
00:05:32,630 --> 00:05:35,230
How do you get into it and how do you get out of it.

77
00:05:35,240 --> 00:05:38,540
The terminal actually shows us the instructions right here.

78
00:05:38,630 --> 00:05:44,960
So I can even copy this pasted in or just type it and kinda activate and then the name of the environment.

79
00:05:45,080 --> 00:05:51,710
And if you hit enter then you should see a change in your prompt instead of reading base in the beginning.

80
00:05:51,710 --> 00:05:56,510
You should see it read converter underscore environment at this point.

81
00:05:56,510 --> 00:05:59,190
Anything you type here will be a command.

82
00:05:59,280 --> 00:06:04,100
That's specific to this particular environment that you set up and took it out of it.

83
00:06:04,100 --> 00:06:10,500
You simply type Conda deactivate just like it says in the instruction above.

84
00:06:10,670 --> 00:06:18,840
And when you do that the command prompt changes back to base now that we've got our environment setup

85
00:06:19,230 --> 00:06:21,470
we're ready to take the next step.

86
00:06:21,480 --> 00:06:29,430
Now there's one little thing that all the windows users have to do first though and that thing is changing

87
00:06:29,580 --> 00:06:33,780
the maximum character limit for our path.

88
00:06:33,960 --> 00:06:41,100
And that's a special extra step for everybody using Windows because by default you've got a 260 character

89
00:06:41,100 --> 00:06:44,790
limit on the path to a particular file.

90
00:06:44,790 --> 00:06:51,870
So that's that piece of text at the very top in your folder that reads C colon slash users slash your

91
00:06:51,870 --> 00:06:54,960
username slash whatever sub folders you've got.

92
00:06:55,080 --> 00:06:57,240
And then the file name at the end.

93
00:06:57,240 --> 00:07:04,170
So by default Windows for historical reasons has had a limit on how many characters there can be in

94
00:07:04,170 --> 00:07:05,290
total here.

95
00:07:05,400 --> 00:07:11,730
And because this 260 character limit will give us a little bit of a problem when we're installing tensor

96
00:07:11,730 --> 00:07:12,090
flow.

97
00:07:12,090 --> 00:07:19,340
Yes we have to lift this limit beforehand and for that we have to go into the Windows Registry Editor.

98
00:07:19,680 --> 00:07:26,550
And the way you would do this on Windows is you simply search for the Registry Editor by typing Reg

99
00:07:26,640 --> 00:07:28,620
edit into the search ball.

100
00:07:28,830 --> 00:07:34,650
And when you click on it you give permission to make changes and then you should see your Windows Registry

101
00:07:34,650 --> 00:07:36,150
pop up at this point.

102
00:07:36,150 --> 00:07:39,960
You have to navigate to a particular place in the registry.

103
00:07:40,140 --> 00:07:48,960
So go to each key local machine then go to system then go to current controls set expand the folder

104
00:07:48,990 --> 00:07:54,460
that reads control and then scroll down a bit until you see filesystem

105
00:07:57,290 --> 00:08:03,600
and inside file system you should see an entry that reads long paths enabled.

106
00:08:03,710 --> 00:08:07,560
So at the very top of the Registry Editor you should see what I have right here.

107
00:08:08,060 --> 00:08:15,740
Each key local machine system current controls set control and then file system double click on long

108
00:08:15,740 --> 00:08:17,630
paths enabled.

109
00:08:17,780 --> 00:08:24,200
And if you've still got the limit in place on two hundred sixty characters then you should see a zero

110
00:08:24,200 --> 00:08:24,950
there.

111
00:08:25,130 --> 00:08:33,800
And what you need to do at this point is you need to change that zero to a one then click OK and then

112
00:08:33,950 --> 00:08:35,810
simply restart your computer.

113
00:08:38,320 --> 00:08:38,900
That way.

114
00:08:38,980 --> 00:08:42,170
The changes will take effect all right.

115
00:08:42,180 --> 00:08:48,750
So now that we've set up our converter environment and we've lifted the 260 character limit.

116
00:08:48,900 --> 00:08:52,910
If you're on Windows the next step is installing tensor flow.

117
00:08:52,980 --> 00:08:59,160
J.S. and the we we're gonna do this is first we're going to activate the converter environment that

118
00:08:59,160 --> 00:09:04,440
we've just set up and so we should see our prompt change and we should see the converter environment

119
00:09:04,500 --> 00:09:09,630
reflected in the beginning of the prompt and then we're going to install tensor flow Jesus and the way

120
00:09:09,630 --> 00:09:16,080
this is gonna work is we're going to issue a command called pip install followed by the package name

121
00:09:16,410 --> 00:09:20,860
and then the version of tensor flow Jesus that we're looking to install.

122
00:09:20,880 --> 00:09:24,270
So Pip stands for Pip install packages.

123
00:09:24,270 --> 00:09:27,460
And yes the abbreviation has the word Pip again.

124
00:09:27,780 --> 00:09:34,620
So there there's some more python in jokes for you but the command that we're going to type into the

125
00:09:34,620 --> 00:09:40,620
terminal or into the kind prompt if you're in windows is Pip install tensor flow G as W equals.

126
00:09:41,190 --> 00:09:47,300
And then we're gonna go for a very particular version which I know works and that's version 1.0.

127
00:09:47,310 --> 00:09:49,520
Two point three.

128
00:09:49,590 --> 00:09:59,580
So here's how it's going to look pip install tensor flow G.S. W equals one point two point three.

129
00:09:59,580 --> 00:10:04,310
So there's some line wrapping happening here but this is all one line one command.

130
00:10:05,070 --> 00:10:10,390
If it enter it's gonna take a little while for tens of low just to be installed.

131
00:10:10,800 --> 00:10:15,270
So there's gonna be some downloads happening and the way you know that it's finished is that you should

132
00:10:15,270 --> 00:10:16,770
see your prompt appear again.

133
00:10:16,770 --> 00:10:23,100
So if you see this blinking cursor in front of your name then you know it's done now.

134
00:10:23,110 --> 00:10:27,770
The next step is actually running the tensor flow J.S. converter because now you've got tense flow.

135
00:10:27,770 --> 00:10:28,860
Yes right.

136
00:10:28,870 --> 00:10:31,090
So how do we do that.

137
00:10:31,210 --> 00:10:37,630
The detailed instructions of course are on the Github page for the tensor flow gas converter and scrolling

138
00:10:37,630 --> 00:10:39,490
down we see that for a saved model.

139
00:10:39,490 --> 00:10:41,050
This is an example.

140
00:10:41,080 --> 00:10:43,340
Now how does this actually translate for us.

141
00:10:43,570 --> 00:10:48,430
Now even though these instructions are not bad it's even simpler for us actually.

142
00:10:48,460 --> 00:10:54,950
So the only thing that we have to type into the anaconda prompt or into the terminal is tense offload

143
00:10:55,030 --> 00:11:01,480
J.S. underscore converter which is the command and then we have to supply a couple of inputs.

144
00:11:01,480 --> 00:11:06,480
The first one is what the format is that we're going to be converting from.

145
00:11:06,910 --> 00:11:12,980
And that's a 10 serve flow saved model T F underscore saved on a screen model.

146
00:11:13,090 --> 00:11:17,110
The next thing that we have to provide is the output format that we're looking for.

147
00:11:17,110 --> 00:11:20,850
And this is a tensor flow J.S. graph model.

148
00:11:20,920 --> 00:11:26,620
Again the spelling has very important and you're going to have to spell everything exactly as you see

149
00:11:26,620 --> 00:11:29,650
here for this to work.

150
00:11:29,770 --> 00:11:32,490
Now you have to supply two more things.

151
00:11:32,530 --> 00:11:36,310
The first is where to find the saved model files.

152
00:11:36,310 --> 00:11:39,950
So these are the PDB files that we generated from Jupiter.

153
00:11:40,480 --> 00:11:44,730
And the next thing is where the output files should be stored.

154
00:11:44,740 --> 00:11:50,270
So this is the folder where the Converter will put the output files and that's it.

155
00:11:50,270 --> 00:11:56,420
Actually it's gonna be a little bit of typing but it's actually just these four things.

156
00:11:56,440 --> 00:11:56,860
All right.

157
00:11:56,880 --> 00:11:58,870
So how's this actually gonna work in practice.

158
00:11:59,200 --> 00:12:05,980
Well let me show you in the terminal it's gonna be tensor flow J.S. underscore converter.

159
00:12:05,980 --> 00:12:07,430
So that's the command.

160
00:12:07,780 --> 00:12:16,740
And then it's gonna be two hyphens with input underscore format equal to T F underscore saved underscore

161
00:12:17,320 --> 00:12:24,390
model then our second input that we're gonna provide is the output on a score format and that's gonna

162
00:12:24,400 --> 00:12:30,830
be equal to TFG s underscore graph on the score model.

163
00:12:30,850 --> 00:12:34,120
Now before you continue on just double check the spelling here.

164
00:12:34,330 --> 00:12:37,990
Make sure you've got no typos in this incantation.

165
00:12:37,990 --> 00:12:39,840
Otherwise we're going to have a problem.

166
00:12:39,880 --> 00:12:41,860
So everything's lowercase.

167
00:12:42,040 --> 00:12:44,520
You've got the underscores where they need to be.

168
00:12:44,560 --> 00:12:46,930
You've got double hyphens where they need to be.

169
00:12:47,440 --> 00:12:51,050
And if you've got some line wrapping Don't worry about it.

170
00:12:51,070 --> 00:12:54,420
So once you're happy with that you can provide the third input.

171
00:12:54,820 --> 00:12:57,890
And that's where those saved model files are saved.

172
00:12:57,890 --> 00:13:04,930
Now all you need to do is drag and drop the directory in to your command prompt and so you can just

173
00:13:05,290 --> 00:13:12,460
drag and drop it in and you'll get the full path of where to find that file and your variable files

174
00:13:12,580 --> 00:13:13,900
and so on.

175
00:13:13,900 --> 00:13:21,780
So that's the third input and the fourth input is where you want the converter to spit out its results.

176
00:13:21,850 --> 00:13:27,070
And so in this case I recommend creating a new folder in your projects folder and you can call this

177
00:13:27,070 --> 00:13:30,580
folder anything you like but I'm gonna go for TFG yes.

178
00:13:30,820 --> 00:13:37,090
And I want to take that folder and I'm going to drag and drop it into the command prompt again to get

179
00:13:37,090 --> 00:13:39,790
the full path to this folder.

180
00:13:39,910 --> 00:13:44,160
And once you're happy with that you can actually run the converter and let's see what happens.

181
00:13:44,350 --> 00:13:49,870
The converter actually doesn't take very much time to run and once it's done and you should see no error

182
00:13:49,870 --> 00:13:55,690
messages at this point you should see this TFG s folder that you've just created populated with two

183
00:13:55,690 --> 00:14:02,820
files the first file is gonna read something like group one short one of one.

184
00:14:02,890 --> 00:14:05,550
And the second file is gonna be your model.

185
00:14:05,560 --> 00:14:06,790
Don't Jason.

186
00:14:06,790 --> 00:14:09,950
Now again if you had any problems any errors.

187
00:14:10,090 --> 00:14:16,270
I'm actually gonna add these two files under the lesson resources so that you can download them in case

188
00:14:16,270 --> 00:14:22,180
you get stuck and you don't have to spend a just troubleshooting the tensor flow just convert them but

189
00:14:22,420 --> 00:14:24,000
I hope this worked for you.

190
00:14:24,010 --> 00:14:30,820
And if you're wondering what this is then you've got on one hand the actual graph and you can see this

191
00:14:30,820 --> 00:14:31,960
beautifully.

192
00:14:31,960 --> 00:14:38,170
If you open it in something like the Firefox browser which formats this Jason File very very nicely

193
00:14:38,770 --> 00:14:43,270
and then this other file here you've got the actual weights of your neural network.

194
00:14:43,360 --> 00:14:44,510
So here's your model.

195
00:14:44,710 --> 00:14:46,440
And these are gonna be your weights.

196
00:14:46,540 --> 00:14:51,640
Now these are gonna be much harder to inspect because this is a binary you're not actually gonna be

197
00:14:51,640 --> 00:14:54,070
able to open this in a program and make sense of it.

198
00:14:54,820 --> 00:14:55,990
So there you go.

199
00:14:55,990 --> 00:15:01,150
Congratulations on successfully converting a tense flow model to a tense flow J.

200
00:15:01,150 --> 00:15:03,790
S model in the next lesson.

201
00:15:03,880 --> 00:15:08,380
We're gonna be starting to look at the Web site that we're gonna build we're going to look at these.

202
00:15:08,380 --> 00:15:12,990
The project I'm going to start learning about h Tim L and CSX.

203
00:15:13,060 --> 00:15:13,770
I'll see you there.
