Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 78321c3

Browse files
Merge pull request #6 from zou000/update
* update swift-tensorflow to latest version
2 parents 5f29d1c + a0b91b5 commit 78321c3

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

‎4.2/Dockerfile‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ RUN apt-get -q update && \
2929
# Install Swift for TensorFlow:
3030

3131
# Define SWIFT_TF_URL as an arg that can be passed by users if needed
32-
ARG SWIFT_TF_URL=https://storage.googleapis.com/swift-tensorflow/ubuntu16.04/swift-tensorflow-DEVELOPMENT-2018年04月26日-a-ubuntu16.04.tar.gz
32+
ARG SWIFT_TF_URL=https://storage.googleapis.com/swift-tensorflow/ubuntu16.04/swift-tensorflow-DEVELOPMENT-2019年01月04日-a-ubuntu16.04.tar.gz
3333

3434
RUN curl -fSsL $SWIFT_TF_URL -o swift-tensorflow.tar.gz \
35-
&& tar xzf swift-tensorflow.tar.gz --directory /
35+
&& tar xzf swift-tensorflow.tar.gz --directory / \
36+
&& rm swift-tensorflow.tar.gz
37+
38+
# Version DEVELOPMENT-2019年01月04日 needs this fix
39+
RUN mv -n /usr/lib/libBlocksRuntime.so /usr/lib/libBlocksRuntime.so.0 && ldconfig
3640

3741
RUN swift --version
3842

3943
RUN cd /usr/src
40-
WORKDIR /usr/src
44+
WORKDIR /usr/src

‎README.md‎

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,53 @@ This image will allow you to easily take the official [Swift for TensorFlow](htt
1616
```bash
1717
docker run --rm --security-opt seccomp:unconfined -itv ${PWD}:/usr/src \
1818
zachgray/swift-tensorflow:4.2 \
19-
swift -I/usr/lib/swift/clang/include
19+
swift
2020
```
2121

2222
#### Observe the output:
2323

2424
```
25-
Welcome to Swift version 4.2-dev (LLVM 04bdb56f3d, Clang b44dbbdf44). Type :help for assistance.
26-
1>
25+
Welcome to Swift version 4.2-dev (LLVM fd66ce58db, Clang cca52e8396, Swift 280486afdc).
26+
Type :help for assistance.
27+
1>
2728
```
2829

2930
#### Interact with TensorFlow:
3031

3132
```
3233
1> import TensorFlow
33-
2> var x = Tensor([[1, 2], [3, 4]])
34-
2018年04月27日 04:30:17.505272: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
35-
x: TensorFlow.Tensor<Double> = [[1.0, 2.0], [3.0, 4.0]]
34+
2> var x = Tensor<Float>([[1, 2], [3, 4]])
35+
x: TensorFlow.Tensor<Float> = [[1.0, 2.0], [3.0, 4.0]]
3636
3> x + x
37-
$R0: TensorFlow.Tensor<Double> = [[2.0, 4.0], [6.0, 8.0]]
37+
$R2: TensorFlow.Tensor<Float> = [[2.0, 4.0], [6.0, 8.0]]
3838
4> :exit
3939
```
4040

4141
### Run the Interpreter
4242

43-
Assuming you've added a swift file ([like this one shown in the official docs](https://github.com/tensorflow/swift/blob/master/Usage.md#interpreter)) in your current directory with the name `inference.swift`:
43+
Assuming you've added a swift file, like this one copied from [official docs](https://github.com/tensorflow/swift/blob/master/Usage.md#interpreter) in your current directory with the name `inference.swift`:
44+
45+
```swift
46+
import TensorFlow
47+
48+
struct MLPClassifier {
49+
var w1 = Tensor<Float>(shape: [2, 4], repeating: 0.1)
50+
var w2 = Tensor<Float>(shape: [4, 1], scalars: [0.4, -0.5, -0.5, 0.4])
51+
var b1 = Tensor<Float>([0.2, -0.3, -0.3, 0.2])
52+
var b2 = Tensor<Float>([[0.4]])
53+
54+
func prediction(for x: Tensor<Float>) -> Tensor<Float> {
55+
let o1 = tanh(matmul(x, w1) + b1)
56+
return tanh(matmul(o1, w2) + b2)
57+
}
58+
}
59+
let input = Tensor<Float>([[0.2, 0.8]])
60+
let classifier = MLPClassifier()
61+
let prediction = classifier.prediction(for: input)
62+
print(prediction)
63+
```
64+
65+
To use the interpreter:
4466

4567
```bash
4668
docker run --rm -v ${PWD}:/usr/src \
@@ -52,7 +74,7 @@ docker run --rm -v ${PWD}:/usr/src \
5274

5375
```bash
5476
docker run --rm -v ${PWD}:/usr/src zachgray/swift-tensorflow:4.2 \
55-
swiftc -O /usr/src/inference.swift
77+
swiftc -O /usr/src/inference.swift -ltensorflow
5678
```
5779

5880
## Run with Dependencies (advanced)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /