Manufacturers/suppliers of electronic components describe their products in datasheets. You can read UTMEL's (SHARP's) datasheet for PC817 optocoupler online.
Table Electro-optical Characteristics (page 4) specifies the photodiode current and forward voltage in the first row, where the column Parameter content is Forward Voltage. Photodiode voltage (values in columns MIN, TYP, MAX) is the voltage drop across the IR photodiode. This parameter is measured with the current through the photodiode as specified in column Conditions, \$I_F=20mA\$.
With these parameters, you can estimate the R2 value in the network SENSOR_OUT, R2, PC817 pin1 of your drawing. Take the typical forward voltage of 1.2V and the current of 20mA. This resistor is required if your sensor can sink current too great for your optocoupler and you should constrain the current to the values specified in the datasheet (\$I_F\$ MAX 50mA, typical 20mA).
If your sensor outputs a voltage signal of max 12V, you should select a resistor \$R_D\$ so that it provides a current of 20mA when the voltage across this resistor is 12V-1.2V=10.8V, so \$R_D\$=10.8V/20mA=540 Ohm. The calculated values are approximate values, you only have to guarantee that the currents/voltages are not violating Absolute Maximum Ratings (page 4) and at the same time the photodiode current is sufficient to safely turn the transistor on with IR light of the photodiode. If your signal is current and it is greater than 50mA, you can use a shunt to sink excessive current.
UTMEL's document PC817 Photocoupler Application, Pinout and Datasheet gives an example of using PC817, section How to use PC817, where the author uses \$R_L\$ = 1K to pull high the collector pin of the transistor. More advanced use of the optocoupler requires the designer to adjust the time parameters and frequency response, varying the pullup resistor value \$R_L\$, see page 8 of the datasheet, Figs 13-16.
Here I'm giving you only introductory instructions on selection of resistor values. More advanced designs would require adapting the circuit to detection of spike-shaped vs. continuous signal levels, optimizing the timing or frequency parameters and maybe other adjustments with other circuit components besides resistors.