# Import pretrained Keras model in Julia for inference

**URL:** https://discourse.julialang.org/t/import-pretrained-keras-model-in-julia-for-inference/104924
**Category:** Machine Learning
**Created:** [October 13, 2023, 9:28am UTC](https://discourse.julialang.org/t/import-pretrained-keras-model-in-julia-for-inference/104924 "2023-10-13T09:28:04Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![dubosipsl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dubosipsl/32/52998_2.png) [@dubosipsl](https://discourse.julialang.org/u/dubosipsl)
#### Post date: [October 21, 2023, 7:34pm UTC](https://discourse.julialang.org/t/import-pretrained-keras-model-in-julia-for-inference/104924/6 "2023-10-21T19:34:32Z")

</div>

To conclude : after trying ONNX and PyCall I am quite happy with PyCall. Here is an example:

```julia
using PyCall: @pyimport
import Images

@pyimport tensorflow as tf
infer(model, x) = model(tf.constant(x)).numpy()

img = Images.imresize(Images.load("data/elephant.jpg"), (224, 224))
rgb = [Float32(getproperty(color, channel)) for z = 1:50, color in img, channel in (:r, :g, :b)]
ResNet50 = tf.keras.applications.resnet50.ResNet50
model = ResNet50(weights = "imagenet")
@time scores = infer(model, rgb);

```

Note that ‘data/elephant.jpg’ is some downloaded picture file.

---

_[View the full topic](https://discourse.julialang.org/t/import-pretrained-keras-model-in-julia-for-inference/104924)._
