or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

advanced-apis.mdindex.mdkeypoints.mdmodel-loading.mdmulti-pose.mdpose-utilities.mdsingle-pose.md

model-loading.mddocs/

0

# Model Loading and Configuration

1

2

PoseNet model loading and configuration system for selecting neural network architectures and performance parameters.

3

4

## Capabilities

5

6

### Load Function

7

8

Loads a PoseNet model with configurable architecture and performance settings.

9

10

```typescript { .api }

11

/**

12

* Load PoseNet model instance from checkpoint with configurable architecture

13

* @param config - Model configuration options, defaults to MobileNetV1 setup

14

* @returns Promise resolving to configured PoseNet instance

15

*/

16

function load(config?: ModelConfig): Promise<PoseNet>;

17

```

18

19

**Usage Examples:**

20

21

```typescript

22

import * as posenet from '@tensorflow-models/posenet';

23

24

// Default MobileNetV1 model (fastest)

25

const net = await posenet.load();

26

27

// MobileNetV1 with custom configuration

28

const mobileNet = await posenet.load({

29

architecture: 'MobileNetV1',

30

outputStride: 16,

31

inputResolution: { width: 640, height: 480 },

32

multiplier: 0.75

33

});

34

35

// ResNet50 model (most accurate)

36

const resNet = await posenet.load({

37

architecture: 'ResNet50',

38

outputStride: 32,

39

inputResolution: { width: 257, height: 200 },

40

quantBytes: 2

41

});

42

43

// Custom model URL

44

const customNet = await posenet.load({

45

architecture: 'MobileNetV1',

46

outputStride: 16,

47

inputResolution: 257,

48

modelUrl: 'https://example.com/custom-posenet-model.json'

49

});

50

```

51

52

### Model Configuration

53

54

Configuration interface for customizing model architecture and performance characteristics.

55

56

```typescript { .api }

57

/**

58

* Configuration options for PoseNet model loading

59

*/

60

interface ModelConfig {

61

/** Neural network architecture: MobileNetV1 (fast) or ResNet50 (accurate) */

62

architecture: PoseNetArchitecture;

63

/** Output stride controlling resolution vs speed trade-off */

64

outputStride: PoseNetOutputStride;

65

/** Input image resolution for processing */

66

inputResolution: InputResolution;

67

/** MobileNetV1 depth multiplier (MobileNetV1 only) */

68

multiplier?: MobileNetMultiplier;

69

/** Custom model URL for local development or restricted access */

70

modelUrl?: string;

71

/** Weight quantization bytes for model size vs accuracy */

72

quantBytes?: PoseNetQuantBytes;

73

}

74

75

type PoseNetArchitecture = 'ResNet50' | 'MobileNetV1';

76

type PoseNetOutputStride = 32 | 16 | 8;

77

type MobileNetMultiplier = 0.50 | 0.75 | 1.0;

78

type PoseNetQuantBytes = 1 | 2 | 4;

79

type InputResolution = number | {width: number, height: number};

80

```

81

82

### Architecture Selection

83

84

Choose between two pre-trained neural network architectures:

85

86

**MobileNetV1:**

87

- Faster inference, smaller model size

88

- Output strides: 8, 16, 32

89

- Multipliers: 0.50, 0.75, 1.0

90

- Recommended for mobile and mid-range devices

91

92

**ResNet50:**

93

- Higher accuracy, larger model size

94

- Output strides: 16, 32

95

- Fixed multiplier: 1.0

96

- Recommended for high-end devices

97

98

### Performance Parameters

99

100

**Output Stride:**

101

- Controls resolution vs speed trade-off

102

- Smaller values (8) = higher accuracy, slower inference

103

- Larger values (32) = lower accuracy, faster inference

104

105

**Input Resolution:**

106

- Image size fed to the model

107

- Higher resolution = more accurate, slower processing

108

- Can be number (square) or {width, height} object

109

110

**Multiplier (MobileNetV1 only):**

111

- Controls model depth (number of channels)

112

- 1.0 = full depth, highest accuracy

113

- 0.50 = half depth, fastest inference

114

- Required to be 1.0 when outputStride is 32

115

116

**Quantization Bytes:**

117

- 4 bytes = no quantization, highest accuracy (~90MB)

118

- 2 bytes = 2x smaller model, slightly lower accuracy (~45MB)

119

- 1 byte = 4x smaller model, lower accuracy (~22MB)

120

121

### Default Configuration

122

123

The default configuration when no parameters are provided:

124

125

```typescript { .api }

126

const MOBILENET_V1_CONFIG: ModelConfig = {

127

architecture: 'MobileNetV1',

128

outputStride: 16,

129

multiplier: 0.75,

130

inputResolution: 257,

131

};

132

```

133

134

### PoseNet Class

135

136

The main class returned by the load function, providing pose estimation methods.

137

138

```typescript { .api }

139

/**

140

* Main PoseNet class for pose estimation

141

*/

142

class PoseNet {

143

/** Underlying neural network model */

144

readonly baseModel: BaseModel;

145

/** Model input resolution as [height, width] */

146

readonly inputResolution: [number, number];

147

148

/** Estimate single person pose from input image */

149

estimateSinglePose(input: PosenetInput, config?: SinglePersonInterfaceConfig): Promise<Pose>;

150

151

/** Estimate multiple person poses from input image */

152

estimateMultiplePoses(input: PosenetInput, config?: MultiPersonInferenceConfig): Promise<Pose[]>;

153

154

/** Release GPU/CPU memory allocated by the model */

155

dispose(): void;

156

}

157

158

type PosenetInput = ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | tf.Tensor3D;

159

```